import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author user
 */
public class MyCanvas extends GameCanvas implements Runnable ,GoldItem{

    final static int TILE_SAND = 19;
    final static int TILE_CAUTRUOT = 20;
    final static int MIN_BUFFER = 40;
    final static int ARROW_LEFT = 5;
    final static int ARROW_RIGHT = 6;
    final static int ARROW_UP = 7;
    final static int ARROW_DOWN = 8;
    final static int LV_SMALL = 2;
    final static int LV_MEDIUM = 10;
    final static int LV_BIG = 20;
    PetCity midlet;
    Thread gameThread;
    GameDesign2 gameDesign;
    boolean isPlay, isPause = false;
    // <editor-fold defaultstate="collapsed" desc="fields">
    int lastDirection, money, numberSkill, numberArena, timeGc, curX = 0, curFightX = 0, noFood, parkWidth = 1170, prevDirect;
    long totalMemory;
    Random r;
    int delay;
    long datePet1, hourPet1, minPet1, timeTrain, timeCoutTrain;
    Font font1 = Font.getFont(0, 0, Font.SIZE_SMALL);
    Font font2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
    Font font3 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL);
    LayerManager lm, lmInfo, lmFight, lmChooseEgg, lmChoosePet, lmAnouceItem, lmPark;
    Player gameMedia, fightMedia;
    Pet pet[], petDoiThu, petDoiThu1[];
    int indexPetChosen, nextLevel[], infoDoithu[][], time, oldX, oldY, arrmap[][], oldICollides = -1, oldICauTruot = -1, prevCauTruot;
    TiledLayer trainArrow, choosenFight, myHPLine, myHpMp, doithuHPline, doithuHpMp, listSkill, addSkill, addMainScreen, listChooseSkill, listAddChooseSkill,
            glass, park, treeUnder, sky, hangraoNgang[];
    Sprite egg1, egg2, myArena, doithuArena, myWind, doithuWind, key, keyUnLock, iconFood;
    Sprite mainMenu[], subMenu1[], subMenu2[], subMenu3[], pointer, bongEgg, /*bongDoiThu,*/ arrowInfo1, arrowInfo2, infoLine[],
            lightTrain, thinking, iconThinking, broom, dust, hit, oneHit, creatHit, doctor, noteBook, pencil, addNenFight, addBackArena,
            face, bottleHP, bottleMP, buffSkill, doithuBuffSkill, oneHitPhandon, dtBottleMP, dtBottleHP, treeBig[], treeSmall[],
            cloudSmall[], cloudBig[], khicauSmall[], khicauBig[], chair[], cautruot[], sand[], sen1[], sen2[], hangraoCanh[], bongDoiThu1[];
    Image light;
    int maxHPDoiThu, maxMPDoiThu, maxHPMe, maxMPMe, noDoctor, moneySavePet, noBottleHP = 1, noBottleMP = 1, doithuBottleHP, doithuBottleMP;
    int iPet, iMainMenu, iSubMenu1, iSubMenu2, iSubMenu3, iPointer, iInfo, topMainMenu, iInputArrow[], iArrow,
            iMenuFight, iChooseFight, iSkill, iRe, iEgg, iChoosePet, iArena, iReBuffSkill, iChooseSkillFight,
            iUpInfo, costUpInfo[], spUpInfo[], iInitPet;
    String sMainMenu[], sSubMenu1[], sSubMenu2[], sSubMenu3[], skillName[], nameArena[];
    boolean isOpenSubMenu, isSubMenuRight, isMainMenuUp, isInfoScreen;
    boolean isMainBeginUp, isMainBeginDown, isSubBeginLeft, isSubBeginRight, isTrainBeginUp, isTrainBeginDown, isLock, isPointMenuRightPressed,
            isPointInfoLeftPress, isPointInfoRightPress, isDrawAnouce = true, isWork, isArrowPressed, isTrainMissed,
            isDrawTrainMiss, isDrawTrainFinish, isAddSkillTrain, isChamsoc, isExitPressed, isOKMssB, isPointerMenuLeftPressed,
            isMenuFight, isChooseFight, isBeginFight, isInfoFight, isAlert, isChoosen, isMssFight, isYourTurn, isHitting, reHitting,
            isLose, isWin, isDoctor, isLearning, isFinishChamsoc, isStartedGame = false, isChooseEgg, isStartTrain, isDrPetThk1, isExitGamePressed,
            isSellPet, isPointOKPresse, isSetVisibleCreat, isDrawNoCareEat, isDrawNoCareLearn, isDrawNoCareClean,
            isDrawNoCareDoctor, isChooseArena, isTrailer, isEating, isDrink, isAttack, isTrungdon, isCanFight, isOkReSkill,
            isPresentItem, isInitMap, isSavePetMss, isOKSavePet, isSavePetSuccess, isSavedPet, isHitSkill2, isCheckHit2 = true, isPresentKey,
            isDrawAnouceFight, isWaitHit6, isWaitReHit6, isReHit2, isCheckReHit2, isMySkill7, isMySkill8, isMySkill9, isMySkill10,
            isReSkill7, isReSkill8, isReSkill9, isReSkill10, isBomMau, isBomMP, isDrawSkillFight, isDrawEmptyFood, isBuyFood, isNotEnoughMoneyBuyFood,
            isBuyHP, isBuyMP, isLoadingWalk, isStartWalk, isCollidesPet, isExitWalk, isDrawInfoDoiThu, isInPutMove, isInputMoveCautruot, isKeyBonus;
    //Trang thai cua thu nuoi
    boolean isThiDau, isTrain, isCleaning, isCaress, isShockScreen, isDoiThuLose[];
    int scoreTrain, needScoreTrain, skillTrain, tiencuoc[];
    int timePoinNhay, timeInfoNhay, timeWaitPointer, timeDrawAnouce, timeTrainMiss, timeTrainFinish, timeAddSkillTrain, timeDrawYourTurn, timeWaitReHit,
            timeLose, timeWin, timeDoctor, timeWaitChamsoc, timeStartTrain, timeDrawPetThink1, timeDrawNoCare, timeTrailer, timeCanFight,
            timeDrawAnouceItem, timeShock, timeXTrain, timeSavePet, timeHitSkill2, timeHitSkill6, timeReHit6, timeReHit2, timeWaitChooseSkill,
            time1kChooseSkill, timeDrawNotEnoughMoney, timeLoadingWalk;
    int curYFight, xInfo, xState, pointDragX, pointCaressX, pointDragY, xTrainScreen, xLight, yLight, yMenuFight, iAddMainScreen = 7,
            yNotEnoughMoney;
    //Thông số các Skill
    int mana[], dam[], acc[], doithuAcc[], skilllv[], costSkill[], spSkill[], levelUseSkill[], noUpMyInfo[];
    boolean isUseSkill[];// </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Park">
    int yTreeBig = 64, yTreeSmall = 100, yChair = 118;
    int xTreeBig[] = {0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100},//33,63
            xTreeSmall[] = {54, 87, 150, 183, 246, 279, 342, 375, 438, 471, 534, 567, 620, 653, 716, 749, 812, 845, 908, 941, 1004, 1037},
            xCloudSmall[] = {33, 256, 492, 774, 1050},
            yCloudSmall[] = {14, 25, 14, 34, 0},
            xCloudBig[] = {127, 330, 630, 933},
            yCloudBig[] = {17, 0, 7, 31},
            xKhiCauSmall[] = {82, 546, 975},
            yKhiCauSmall[] = {17, 7, 16},
            xKhiCauBig[] = {175, 381, 804},
            yKhiCauBig[] = {32, 5, 16},
            xChair[] = {48, 162, 276, 390, 504, 618, 732, 846, 960, 1074},
            xCauTruot[] = {145, 592, 1048},
            yCauTruot[] = {98, 113, 245},
            xSand[] = {30},
            ySand[] = {106},
            xSen[] = {558, 739},
            ySen[] = {284, 276},
            xSen1[] = {501, 639, 874},
            ySen1[] = {276, 300, 278},
            xHangRaoNgang[] = {0},
            yHangRaoNgang[] = {130},
            xHangRaoCanh[] = {114}, yHangRaoCanh[] = {115},
            xPetDoiThu1[] = {30, 60, 166, 211, 319, 240, 100, 240, 417, 526, 324, 355, 712, 807, 907, 987, 1044, 1011, 1092, 1128},
            yPetDoiThu1[] = {160, 242, 148, 243, 245, 110, 276, 272, 113, 119, 139, 273, 119, 145, 116, 143, 106, 233, 182, 279};// </editor-fold>

    public MyCanvas(PetCity midlet) {
        super(false);
        setFullScreenMode(true);
        this.midlet = midlet;
        lm = new LayerManager();
        lmInfo = new LayerManager();
        lmFight = new LayerManager();
        lmChoosePet = new LayerManager();
        lmAnouceItem = new LayerManager();
        lmPark = new LayerManager();
        gameDesign = new GameDesign2();
        r = new Random();
        petDoiThu1 = new Pet[20];
        mainMenu = new Sprite[5];
        subMenu1 = new Sprite[5];
        subMenu2 = new Sprite[4];
        subMenu3 = new Sprite[4];
        sMainMenu = new String[mainMenu.length];
        sSubMenu1 = new String[subMenu1.length];
        sSubMenu2 = new String[subMenu2.length];
        sSubMenu3 = new String[subMenu3.length];
        infoLine = new Sprite[subMenu1.length];
        nextLevel = new int[2];
        iInputArrow = new int[4];
        infoDoithu = new int[5][7];
        nameArena = new String[4];
        pet = new Pet[2];
        mana = new int[10];
        dam = new int[10];
        acc = new int[10];
        doithuAcc = new int[10];
        skilllv = new int[10];
        costSkill = new int[10];
        spSkill = new int[10];
        isUseSkill = new boolean[10];
        levelUseSkill = new int[10];
        costUpInfo = new int[4];
        spUpInfo = new int[4];
        noUpMyInfo = new int[4];
    }

    //Ham nap tien
    public void addGold() {
        SendMessageItem sendMI = new SendMessageItem("GMHBT PETCITY", "6711", this);
        new Thread(sendMI).start();
//        isPause = true;
//        midlet.display.setCurrent(midlet.sunnetCanvas);
    }

    public void start() {
        isPlay = true;
        isPause = false;
        gameThread = new Thread(this);
        gameThread.start();
    }

    public void initGameMedia() {
        try {
            InputStream inputStream = this.getClass().getResourceAsStream("country.mid");
            gameMedia = Manager.createPlayer(inputStream, "audio/midi");
            gameMedia.setLoopCount(-1);
            gameMedia.stop();
            inputStream = this.getClass().getResourceAsStream("fighting.mid");
            fightMedia = Manager.createPlayer(inputStream, "audio/midi");
            fightMedia.setLoopCount(-1);
            fightMedia.stop();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initPetWhenStart() throws IOException {
//        if (!petYoYo.infoPet1.isChosenPet) {
//            return;
//        }
        if (midlet.infoPet1.isChosenPet) {
            iPet = 0;
            if (midlet.infoPet1.level < 1) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga(), 26, 40), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga128(), 16, 25), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_EGG, pet[iPet].chickEggSwayseq);
            } else if (midlet.infoPet1.level < 2) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga(), 26, 40), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga128(), 16, 25), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_EGG_NUT, pet[iPet].chickEggNutseq);
            }
            if (midlet.infoPet1.level >= 2 && midlet.infoPet1.level < MyCanvas.LV_MEDIUM) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaCon(), 40, 40), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaCon128(), 25, 25), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_CHICK_SMALL, pet[iPet].chickBabyseq);
            }
            if (midlet.infoPet1.level >= LV_MEDIUM && midlet.infoPet1.level < MyCanvas.LV_BIG) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaTrungBinh(), 60, 60), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaTrungBinh128(), 40, 40), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_CHICK_MEDIUM, pet[iPet].chickMediumseq);
            }
            if (midlet.infoPet1.level >= LV_BIG) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaLon(), 70, 70), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaLon128(), 45, 45), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_CHICK_BIG, pet[iPet].chickMediumseq);
            }
            lmChoosePet.append(pet[iPet].pet);
            pet[iPet].level = midlet.infoPet1.level;
            pet[iPet].exp = midlet.infoPet1.exp;
            pet[iPet].skillPoint = midlet.infoPet1.skillPoint;
            pet[iPet].mp = midlet.infoPet1.mp;
            pet[iPet].hp = midlet.infoPet1.hp;
            pet[iPet].attack = midlet.infoPet1.attack;
            pet[iPet].defend = midlet.infoPet1.defend;
            pet[iPet].title = midlet.infoPet1.title;
            pet[iPet].foodPoint = midlet.infoPet1.foodPoint;
            pet[iPet].relaxPoint = midlet.infoPet1.relaxPoint;
            pet[iPet].learnPoint = midlet.infoPet1.learnPoint;
            pet[iPet].helthPoint = midlet.infoPet1.helthPoint;
            pet[iPet].cleanPoint = midlet.infoPet1.cleanPoint;
            noBottleHP = midlet.infoPet1.noBottleHp;
            noBottleMP = midlet.infoPet1.noBottleMP;
            noFood = midlet.infoPet1.noFood;
            pet[iPet].cost = 250 + pet[iPet].level * 50;
//                nextLevel[0] = (pet[iPet].level + 1) * 30;
            checkExpNextLevel(iPet);
//                if (!midlet.infoPet1.isTired) {
//                    checkSystemTime();
//                }
        }
        if (midlet.infoPet2.isChosenPet) {
            iPet = 1;
            if (midlet.infoPet2.level < 1) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga(), 26, 40), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga128(), 16, 25), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_EGG, pet[iPet].chickEggSwayseq);
            } else if (midlet.infoPet2.level < 2) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga(), 26, 40), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga128(), 16, 25), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_EGG_NUT, pet[iPet].chickEggNutseq);
            }
            if (midlet.infoPet2.level >= 2 && midlet.infoPet2.level < MyCanvas.LV_MEDIUM) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaCon(), 40, 40), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaCon128(), 25, 25), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_CHICK_SMALL, pet[iPet].chickBabyseq);
            }
            if (midlet.infoPet2.level >= LV_MEDIUM && midlet.infoPet2.level < MyCanvas.LV_BIG) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaTrungBinh(), 60, 60), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaTrungBinh128(), 40, 40), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_CHICK_MEDIUM, pet[iPet].chickMediumseq);
            }
            if (midlet.infoPet2.level >= LV_BIG) {
                if (this.getWidth() >= 200) {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaLon(), 70, 70), Pet.CHICK);
                } else {
                    pet[iPet] = new Pet(new Sprite(gameDesign.getGaLon128(), 45, 45), Pet.CHICK);
                }
                pet[iPet].setState(Pet.STATE_CHICK_BIG, pet[iPet].chickMediumseq);
            }
            lmChoosePet.append(pet[iPet].pet);
            pet[iPet].level = midlet.infoPet2.level;
            pet[iPet].exp = midlet.infoPet2.exp;
            pet[iPet].skillPoint = midlet.infoPet2.skillPoint;
            pet[iPet].mp = midlet.infoPet2.mp;
            pet[iPet].hp = midlet.infoPet2.hp;
            pet[iPet].attack = midlet.infoPet2.attack;
            pet[iPet].defend = midlet.infoPet2.defend;
            pet[iPet].title = midlet.infoPet2.title;
            pet[iPet].foodPoint = midlet.infoPet2.foodPoint;
            pet[iPet].relaxPoint = midlet.infoPet2.relaxPoint;
            pet[iPet].learnPoint = midlet.infoPet2.learnPoint;
            pet[iPet].helthPoint = midlet.infoPet2.helthPoint;
            pet[iPet].cleanPoint = midlet.infoPet2.cleanPoint;
            noBottleHP = midlet.infoPet2.noBottleHp;
            noBottleMP = midlet.infoPet2.noBottleMP;
            noFood = midlet.infoPet2.noFood;
            pet[iPet].cost = 250 + pet[iPet].level * 50;
//                nextLevel[0] = (pet[iPet].level + 1) * 30;
            checkExpNextLevel(iPet);
//                if (!midlet.infoPet2.isTired) {
//                    checkSystemTime();
//                }
        }
    }

    public void initSprite() {
        try {
            bongEgg = gameDesign.getBongEgg();
//            bongDoiThu = new Sprite(gameDesign.getBong(), 35, 35);
//            backGround = gameDesign.getBackGround();
            for (int i = 0; i < mainMenu.length; i++) {
                mainMenu[i] = new Sprite(gameDesign.getMain_menu(), 40, 40);
                mainMenu[i].setVisible(true);
                mainMenu[i].setFrame(i);
                mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), topMainMenu);
                lm.append(mainMenu[i]);
            }
            pointer = gameDesign.getPointer();
            pointer.setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[0].getWidth() / 2, topMainMenu);
            lm.append(pointer);
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i] = new Sprite(gameDesign.getSub_Chamsoc(), 40, 40);
                subMenu1[i].setVisible(true);
                subMenu1[i].setFrame(i);
                subMenu1[i].setPosition((i - subMenu1.length) * subMenu1[i].getWidth(), topMainMenu);
                lm.append(subMenu1[i]);
                lmInfo.append(subMenu1[i]);
            }
            for (int i = 0; i < subMenu3.length; i++) {
                subMenu3[i] = new Sprite(gameDesign.getSub_Shopping(), 40, 40);
                subMenu3[i].setVisible(true);
                subMenu3[i].setFrame(i);
                subMenu3[i].setPosition((i - subMenu3.length) * subMenu3[i].getWidth(), topMainMenu);
                lm.append(subMenu3[i]);
            }
            arrowInfo1 = new Sprite(gameDesign.getArt2(), 16, 24);
            arrowInfo2 = new Sprite(gameDesign.getArt2(), 16, 24);
            for (int i = 0; i < infoLine.length; i++) {
                infoLine[i] = new Sprite(gameDesign.getInfoLife(), 90, 5);
            }
            trainArrow = gameDesign.getTrainArrow();
            lightTrain = gameDesign.getLight_train();
            light = gameDesign.getLight();
            thinking = gameDesign.getThinking();
            iconThinking = new Sprite(gameDesign.getIcon_trangthai240(), 30, 30);
            iconThinking.setFrameSequence(gameDesign.iconThinkingseq001);
            broom = gameDesign.getBroom();
            dust = gameDesign.getDust();
            choosenFight = gameDesign.getChooseFight();
            myHPLine = new TiledLayer(1, 2, gameDesign.getMau(), 104, 8);
            doithuHPline = new TiledLayer(1, 2, gameDesign.getMau(), 104, 8);
            int[][] tiles = {
                {1},
                {1}
            };
            for (int row = 0; row < 2; row++) {
                for (int col = 0; col < 1; col++) {
                    myHPLine.setCell(col, row, tiles[row][col]);
                    doithuHPline.setCell(col, row, tiles[row][col]);
                }
            }
            myHpMp = new TiledLayer(1, 2, gameDesign.getMau(), 104, 8);
            doithuHpMp = new TiledLayer(1, 2, gameDesign.getMau(), 104, 8);
            int[][] tiles1 = {
                {2},
                {3}
            };
            for (int row = 0; row < 2; row++) {
                for (int col = 0; col < 1; col++) {
                    myHpMp.setCell(col, row, tiles1[row][col]);
                    doithuHpMp.setCell(col, row, tiles1[row][col]);
                }
            }
            listSkill = gameDesign.getListSkill();
            oneHit = gameDesign.getOneHit1();
            oneHitPhandon = new Sprite(gameDesign.getGa_trung_don1(), 60, 60);
            oneHitPhandon.setFrameSequence(gameDesign.oneHit1seq001);
//            creatHit = gameDesign.getCreatHit();
            hit = gameDesign.getChickBabySkill4();
            buffSkill = gameDesign.getChickBabySkill7();
            doithuBuffSkill = gameDesign.getChickBabySkill8();
            doctor = gameDesign.getDoctor();
            noteBook = gameDesign.getNoteBook();
            pencil = gameDesign.getPencil();
            egg1 = new Sprite(gameDesign.getTrungga(), 26, 40);
            egg1.setFrameSequence(gameDesign.chickEggseq002);
            egg2 = new Sprite(gameDesign.getTrungga(), 26, 40);
            egg2.setFrameSequence(gameDesign.chickEggseq002);
            myArena = new Sprite(gameDesign.getDau_truong1(), 240, 160);
            doithuArena = new Sprite(gameDesign.getDau_truong1(), 240, 160);
            addSkill = gameDesign.getAddSkill();
            myWind = gameDesign.getWind();
            doithuWind = new Sprite(gameDesign.getGio(), 240, 120);
            doithuWind.setFrameSequence(gameDesign.windseq001);
            addNenFight = gameDesign.getAddNenFight();
            key = new Sprite(gameDesign.getKhoa(), 25, 25);
            key.setFrameSequence(gameDesign.keyseq001);
            keyUnLock = new Sprite(gameDesign.getKhoa(), 25, 25);
            keyUnLock.setFrameSequence(gameDesign.keyseq002);
            addBackArena = new Sprite(gameDesign.getChe_dau_truong(), 240, 160);
            face = gameDesign.getFace();
            addMainScreen = gameDesign.getAddMainScreen();
            bottleHP = gameDesign.getBottle_hp();
            bottleMP = gameDesign.getBottle_mp();
            dtBottleHP = new Sprite(gameDesign.getBinh_mau_mp(), 10, 12);
            dtBottleHP.setFrameSequence(gameDesign.bottle_hpseq001);
            dtBottleMP = new Sprite(gameDesign.getBinh_mau_mp(), 10, 12);
            dtBottleMP.setFrameSequence(gameDesign.bottle_mpseq001);
            listChooseSkill = gameDesign.getListChooseSkill();
            listAddChooseSkill = gameDesign.getListAddChooseSkill();
            iconFood = gameDesign.getIconFood();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initSprite128() {
        try {
            bongEgg = gameDesign.getBongEgg128();
//            bongDoiThu = new Sprite(gameDesign.getBong(), 35, 35);
//            backGround = gameDesign.getBackGround();
            for (int i = 0; i < mainMenu.length; i++) {
                mainMenu[i] = new Sprite(gameDesign.getMain_menu128(), 25, 25);
                mainMenu[i].setVisible(true);
                mainMenu[i].setFrame(i);
                mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), topMainMenu);
                lm.append(mainMenu[i]);
            }
            pointer = gameDesign.getPointer128();
//            pointer.setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[0].getWidth() / 2, topMainMenu);
            lm.append(pointer);
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i] = new Sprite(gameDesign.getSub_chamsoc128(), 25, 25);
                subMenu1[i].setVisible(true);
                subMenu1[i].setFrame(i);
                subMenu1[i].setPosition((i - subMenu1.length) * subMenu1[i].getWidth(), topMainMenu);
                lm.append(subMenu1[i]);
                lmInfo.append(subMenu1[i]);
            }
            for (int i = 0; i < subMenu3.length; i++) {
                subMenu3[i] = new Sprite(gameDesign.getSub_shopping128(), 25, 25);
                subMenu3[i].setVisible(true);
                subMenu3[i].setFrame(i);
                subMenu3[i].setPosition((i - subMenu3.length) * subMenu3[i].getWidth(), topMainMenu);
                lm.append(subMenu3[i]);
            }
            arrowInfo1 = new Sprite(gameDesign.getArt2(), 16, 24);
            arrowInfo2 = new Sprite(gameDesign.getArt2(), 16, 24);
            for (int i = 0; i < infoLine.length; i++) {
                infoLine[i] = new Sprite(gameDesign.getInfoLife128(), 60, 5);
            }
            trainArrow = gameDesign.getTrainArrow128();
            lightTrain = gameDesign.getLight_train();
            light = gameDesign.getLight();
            thinking = gameDesign.getThinking();
            iconThinking = new Sprite(gameDesign.getIcon_trangthai128(), 20, 20);
            iconThinking.setFrameSequence(gameDesign.iconThinkingseq001);
            broom = gameDesign.getBroom128();
            broom.setFrameSequence(gameDesign.broomseq001);
            dust = gameDesign.getDust128();
            dust.setFrameSequence(gameDesign.dustseq001);
            choosenFight = gameDesign.getChosseFight128();
            listSkill = gameDesign.getListSkill128();
            skillName = new String[10];
            oneHit = gameDesign.getOneHit1128();
            oneHitPhandon = new Sprite(gameDesign.getGa_trung_don1128(), 40, 40);
            oneHitPhandon.setFrameSequence(gameDesign.oneHit1seq001);
//            creatHit = gameDesign.getCreatHit();
            hit = gameDesign.getChickBabySkill4128();
            buffSkill = gameDesign.getChickBabySkill7128();
            doithuBuffSkill = gameDesign.getChickBabySkill8128();
            doctor = gameDesign.getDoctor128();
            noteBook = gameDesign.getNoteBook();
            pencil = gameDesign.getPencil();
            egg1 = new Sprite(gameDesign.getTrungga128(), 16, 25);
            egg1.setFrameSequence(gameDesign.chickEggseq002);
            egg2 = new Sprite(gameDesign.getTrungga128(), 16, 25);
            egg2.setFrameSequence(gameDesign.chickEggseq002);
            if (this.getWidth() < 160) {
                if (totalMemory >= 1000000) {
                    myArena = new Sprite(gameDesign.getDau_truong1128(), 128, 100);
                    doithuArena = new Sprite(gameDesign.getDau_truong1128(), 128, 100);
                }
            } else {
                myArena = new Sprite(gameDesign.getDau_truong1(), 240, 160);
                doithuArena = new Sprite(gameDesign.getDau_truong1(), 240, 160);
            }
            addSkill = gameDesign.getAddSkill128();
            if (this.getWidth() > 160) {
                myWind = gameDesign.getWind();
                doithuWind = new Sprite(gameDesign.getGio(), 240, 120);
            }
            if (this.getWidth() > 160) {
                addNenFight = gameDesign.getAddNenFight();
            }
            key = new Sprite(gameDesign.getKhoa(), 25, 25);
            key.setFrameSequence(gameDesign.keyseq001);
            keyUnLock = new Sprite(gameDesign.getKhoa(), 25, 25);
            keyUnLock.setFrameSequence(gameDesign.keyseq002);
            if (this.getWidth() > 160) {
                addBackArena = new Sprite(gameDesign.getChe_dau_truong(), 240, 160);
            }
            face = gameDesign.getFace128();
            face.setFrameSequence(gameDesign.faceseq001);
            if (this.getWidth() > 160) {
                addMainScreen = gameDesign.getAddMainScreen();
            }
            bottleHP = gameDesign.getBottle_hp();
            bottleMP = gameDesign.getBottle_mp();
            dtBottleHP = new Sprite(gameDesign.getBinh_mau_mp(), 10, 12);
            dtBottleHP.setFrameSequence(gameDesign.bottle_hpseq001);
            dtBottleMP = new Sprite(gameDesign.getBinh_mau_mp(), 10, 12);
            dtBottleMP.setFrameSequence(gameDesign.bottle_mpseq001);
            listChooseSkill = gameDesign.getListChooseSkill128();
            listAddChooseSkill = gameDesign.getListAddChooseSkill128();
            iconFood = gameDesign.getIconFood();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initInfoMap() {
        try {
            arrowInfo1.setPosition(0, this.getHeight() / 2 - arrowInfo1.getHeight() / 2);
            arrowInfo1.setVisible(true);
            lmInfo.append(arrowInfo1);
            arrowInfo2.setTransform(Sprite.TRANS_MIRROR);
            arrowInfo2.setPosition(this.getWidth() - arrowInfo2.getWidth(), this.getHeight() / 2 - arrowInfo2.getHeight() / 2);
            arrowInfo2.setVisible(true);
            lmInfo.append(arrowInfo2);
            for (int i = 0; i < infoLine.length; i++) {
                infoLine[i].setVisible(true);
//                infoLine[i].setPosition(subMenu1[i].getX() + subMenu1[i].getWidth() + 5, subMenu1[i].getY() + font1.getHeight() + 5);
                lmInfo.append(infoLine[i]);
            }
            lmInfo.append(pet[iPet].pet);
            lmInfo.append(key);
            key.setVisible(false);
            lmInfo.append(iconFood);
            iconFood.setVisible(false);
            lmInfo.append(bottleMP);
            bottleHP.setVisible(false);
            lmInfo.append(bottleHP);
            bottleMP.setVisible(false);
            lmInfo.append(listAddChooseSkill);
            listAddChooseSkill.setVisible(false);
            lmInfo.append(listChooseSkill);
            listChooseSkill.setVisible(false);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initFightMap() {
        try {
            lmFight.append(doithuBuffSkill);
            doithuBuffSkill.setVisible(false);
            lmFight.append(buffSkill);
            buffSkill.setVisible(false);
            lmFight.append(addSkill);
            addSkill.setVisible(false);
            lmFight.append(listSkill);
            listSkill.setVisible(false);
//            listSkill.setPosition(3 * this.getHeight() / 4 - listSkill.getHeight() / 2, pet1.pet.getX() + 10);
            lmFight.append(bottleHP);
            bottleHP.setVisible(false);
            lmFight.append(bottleMP);
            bottleMP.setVisible(false);
            lmFight.append(dtBottleHP);
            dtBottleHP.setVisible(false);
            lmFight.append(dtBottleMP);
            dtBottleMP.setVisible(false);
            lmFight.append(pet[iPet].pet);
            lmFight.append(hit);
            hit.setVisible(false);
            if (this.getWidth() > 160) {
                lmFight.append(myWind);
                myWind.setVisible(false);
                lmFight.append(doithuWind);
                doithuWind.setVisible(false);
            }
//            pet[iPet].pet.setVisible(false);
//            lmFight.append(bongEgg);
            lmFight.append(choosenFight);
            choosenFight.setVisible(false);
            if (this.getWidth() > 200) {
                lmFight.append(myHPLine);
                lmFight.append(myHpMp);
                lmFight.append(doithuHPline);
                lmFight.append(doithuHpMp);
            }
//            lmFight.append(bongDoiThu);
            lmFight.append(keyUnLock);
            keyUnLock.setVisible(false);
            if (this.getWidth() > 160) {
                lmFight.append(addBackArena);
                addBackArena.setVisible(false);
                lmFight.append(addNenFight);
                addNenFight.setVisible(false);
            }
            if (this.getWidth() >= 160) {
                lmFight.append(myArena);
                lmFight.append(doithuArena);
                myArena.setVisible(false);
                doithuArena.setVisible(false);
            } else {
                if (totalMemory >= 1000000) {
                    lmFight.append(myArena);
                    lmFight.append(doithuArena);
                    myArena.setVisible(false);
                    doithuArena.setVisible(false);
                }
            }
            if (this.getWidth() >= 200) {
                myHPLine.setVisible(false);
                myHpMp.setVisible(false);
                doithuHPline.setVisible(false);
                doithuHpMp.setVisible(false);
            }
            if (this.getWidth() >= 200) {
                myHPLine.setPosition(5, this.getHeight() / 2 + 5);
                myHpMp.setPosition(5, this.getHeight() / 2 + 5);
                doithuHPline.setPosition(this.getWidth() - doithuHPline.getWidth() - 5, 5);
                doithuHpMp.setPosition(this.getWidth() - doithuHPline.getWidth() - 5, 5);
                choosenFight.setPosition(this.getWidth() / 2 - choosenFight.getWidth() / 2, font2.getHeight() + 10);
            } else {
                choosenFight.setPosition(this.getWidth() / 2 - choosenFight.getWidth() / 2, font3.getHeight() + 5);
            }
            lmFight.append(listAddChooseSkill);
            listAddChooseSkill.setVisible(false);
            lmFight.append(listChooseSkill);
            listChooseSkill.setVisible(false);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initChooseEggMap() {
        try {
            lmChooseEgg = new LayerManager();
            lmChooseEgg.append(egg1);
            egg1.setVisible(true);
            egg1.setPosition(this.getWidth() / 4 - egg1.getWidth() / 2, this.getHeight() / 2 - egg1.getHeight() / 2);
            lmChooseEgg.append(egg2);
            egg2.setVisible(true);
            egg2.setPosition(3 * this.getWidth() / 4 - egg2.getWidth() / 2, this.getHeight() / 2 - egg2.getHeight() / 2);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initWalkingMap() {
        try {
            lmPark = null;
            lmPark = new LayerManager();
            initPetInPark();
            lmPark.append(pet[iPet].pet);
            pet[iPet].setPosition(5, 3 * this.getHeight() / 4 - 2 * pet[iPet].pet.getHeight());
            isDoiThuLose = new boolean[petDoiThu1.length];
            for (int i = 0; i < petDoiThu1.length; i++) {
                int t = r.nextInt(3);
                if (t == 1) {
                    petDoiThu1[i].pet.setTransform(Sprite.TRANS_MIRROR);
                }
                t = r.nextInt(3) + 1;
                if (t == 1) {
                    petDoiThu1[i].pet.setFrameSequence(pet[iPet].chickBabyseq001);
                } else if (t == 2) {
                    petDoiThu1[i].pet.setFrameSequence(pet[iPet].chickBabyseq002);
                } else if (t == 3) {
                    petDoiThu1[i].pet.setFrameSequence(pet[iPet].chickBabyseq003);
                }
//                petDoiThu1[i].setPosition(this.getWidth(), 0);
                petDoiThu1[i].pet.setVisible(true);
                lmPark.append(petDoiThu1[i].pet);
                petDoiThu1[i].setPosition(xPetDoiThu1[i], yPetDoiThu1[i]);
            }
            bongDoiThu1 = new Sprite[petDoiThu1.length];
            for (int i = 0; i < bongDoiThu1.length; i++) {
                bongDoiThu1[i] = new Sprite(gameDesign.getBong128(), 20, 20);
                lmPark.append(bongDoiThu1[i]);
                bongDoiThu1[i].setVisible(false);
                bongDoiThu1[i].setPosition(petDoiThu1[i].pet.getX() + 2, petDoiThu1[i].getY() + petDoiThu1[i].pet.getHeight() - 16);
            }
            int cloud[] = {0, 1};
            cautruot = new Sprite[xCauTruot.length];
            for (int i = 0; i < cautruot.length; i++) {
                cautruot[i] = new Sprite(gameDesign.getCau_truot(), 97, 57);
                cautruot[i].setPosition(xCauTruot[i], yCauTruot[i]);
                lmPark.append(cautruot[i]);
            }
            hangraoNgang = new TiledLayer[xHangRaoNgang.length];
            hangraoNgang[0] = gameDesign.getRaoSand();
            hangraoNgang[0].setPosition(xHangRaoNgang[0], yHangRaoNgang[0]);
            lmPark.append(hangraoNgang[0]);
            hangraoCanh = new Sprite[xHangRaoCanh.length];
            hangraoCanh[0] = new Sprite(gameDesign.getHang_rao(), 32, 38);
            int[] hangRaoseq = {0, 1};
            hangraoCanh[0].setFrameSequence(hangRaoseq);
            hangraoCanh[0].setFrame(1);
            hangraoCanh[0].setPosition(xHangRaoCanh[0], xHangRaoCanh[0]);
            lmPark.append(hangraoCanh[0]);
            sand = new Sprite[xSand.length];
            for (int i = 0; i < sand.length; i++) {
                sand[i] = new Sprite(gameDesign.getBai_cat(), 85, 45);
                sand[i].setPosition(xSand[i], ySand[i]);
                lmPark.append(sand[i]);
            }
            chair = new Sprite[xChair.length];
            for (int i = 0; i < chair.length; i++) {
                chair[i] = new Sprite(gameDesign.getGhe1(), 28, 13);
                chair[i].setPosition(xChair[i], yChair);
                lmPark.append(chair[i]);
            }
            treeBig = new Sprite[xTreeBig.length];
            for (int i = 0; i < treeBig.length; i++) {
                treeBig[i] = new Sprite(gameDesign.getCay_to(), 54, 54);
                treeBig[i].setPosition(xTreeBig[i], yTreeBig);
                lmPark.append(treeBig[i]);
            }
            treeSmall = new Sprite[xTreeSmall.length];
            for (int i = 0; i < treeSmall.length; i++) {
                treeSmall[i] = new Sprite(gameDesign.getCay_nho(), 20, 19);
                treeSmall[i].setPosition(xTreeSmall[i], yTreeSmall);
                lmPark.append(treeSmall[i]);
            }
            khicauBig = new Sprite[xKhiCauBig.length];
            for (int i = 0; i < khicauBig.length; i++) {
                khicauBig[i] = new Sprite(gameDesign.getKhi_cau(), 30, 43);
                khicauBig[i].setFrameSequence(cloud);
                khicauBig[i].setFrame(0);
                khicauBig[i].setPosition(xKhiCauBig[i], yKhiCauBig[i]);
                lmPark.append(khicauBig[i]);
            }
            khicauSmall = new Sprite[xKhiCauSmall.length];
            for (int i = 0; i < khicauSmall.length; i++) {
                khicauSmall[i] = new Sprite(gameDesign.getKhi_cau(), 30, 43);
                khicauSmall[i].setFrameSequence(cloud);
                khicauSmall[i].setFrame(1);
                khicauSmall[i].setPosition(xKhiCauSmall[i], yKhiCauSmall[i]);
                lmPark.append(khicauSmall[i]);
            }
            cloudBig = new Sprite[xCloudBig.length];
            for (int i = 0; i < cloudBig.length; i++) {
                cloudBig[i] = new Sprite(gameDesign.getCloud(), 75, 36);
                cloudBig[i].setFrameSequence(cloud);
                cloudBig[i].setFrame(0);
                cloudBig[i].setPosition(xCloudBig[i], yCloudBig[i]);
                lmPark.append(cloudBig[i]);
            }
            cloudSmall = new Sprite[xCloudSmall.length];
            for (int i = 0; i < cloudSmall.length; i++) {
                cloudSmall[i] = new Sprite(gameDesign.getCloud(), 75, 36);
                cloudSmall[i].setFrameSequence(cloud);
                cloudSmall[i].setFrame(1);
                cloudSmall[i].setPosition(xCloudSmall[i], yCloudSmall[i]);
                lmPark.append(cloudSmall[i]);
            }
            sen1 = new Sprite[xSen.length];
            for (int i = 0; i < sen1.length; i++) {
                sen1[i] = new Sprite(gameDesign.getHoa_sen(), 27, 26);
                sen1[i].setPosition(xSen[i], ySen[i]);
                lmPark.append(sen1[i]);
            }
            sen2 = new Sprite[xSen1.length];
            for (int i = 0; i < sen2.length; i++) {
                sen2[i] = new Sprite(gameDesign.getHoa_sen1(), 28, 28);
                sen2[i].setPosition(xSen1[i], ySen1[i]);
                lmPark.append(sen2[i]);
            }
            treeUnder = gameDesign.getTreeUnder();
            lmPark.append(treeUnder);
            treeUnder.setPosition(0, 88);
            park = gameDesign.getTilePark();
            lmPark.append(park);
            park.setPosition(0, this.getHeight() - park.getHeight());
            glass = gameDesign.getTileGlass();
            lmPark.append(glass);
            glass.setPosition(0, this.getHeight() - glass.getHeight());
            sky = gameDesign.getSky();
            lmPark.append(sky);
            sky.setPosition(0, 0);
//            arrmap = new int[park.getRows()][park.getColumns()];
//            for (int i = 0; i < park.getRows(); i++) {
//                for (int j = 0; j < park.getColumns(); j++) {
//                    arrmap[i][j] = park.getCell(j, i);
//                }
//            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initMainMap() {
        try {
            lm.append(key);
            key.setVisible(false);
            noteBook.setVisible(false);
            pencil.setVisible(false);
            lm.append(pencil);
            lm.append(noteBook);
            doctor.setVisible(false);
            lm.append(doctor);
            broom.setVisible(false);
            lm.append(broom);
            dust.setVisible(false);
            lm.append(dust);
            lm.append(face);
            face.setVisible(false);
            if (pet[0] != null) {
                pet[0].pet.setVisible(false);
            }
            if (pet[1] != null) {
                pet[1].pet.setVisible(false);
            }
            if (this.getWidth() >= 200) {
                pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
            } else {
                pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
            }
            pet[iPet].pet.setVisible(true);
            face.setPosition(this.getWidth() / 2 - face.getWidth() / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - face.getHeight() / 2);
            lm.append(pet[iPet].pet);
            bongEgg.setVisible(true);
            lm.append(bongEgg);
            trainArrow.setPosition(this.getWidth() / 2 - trainArrow.getWidth() / 2, this.getHeight() + 5);
            trainArrow.setVisible(false);
            lm.append(trainArrow);
            iconThinking.setVisible(false);
            lm.append(iconThinking);
            thinking.setVisible(false);
            lm.append(thinking);
            if (this.getWidth() >= 200) {
                gameDesign.updateLayerManagerForBG(lm);
            }
            if (this.getWidth() < 200 && this.getWidth() > 160) {
                gameDesign.updateLayerManagerForBG(lm);
                gameDesign.getBackGround().setPosition(-240 + this.getWidth(), -260 + this.getHeight());
            }
            if (this.getWidth() < 160) {
                gameDesign.updateLayerManagerForBG128(lm);
            }
            initAnouceMap();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initAnouceMap() {
        try {
            lmAnouceItem.append(face);
            face.setVisible(false);
            lmAnouceItem.append(key);
            key.setVisible(false);
            if (this.getWidth() > 160) {
                lmAnouceItem.append(addMainScreen);
                addMainScreen.setVisible(false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void initPetInPark() throws IOException {
        setInfoDoiThu(0);
        if (pet[iPet].state == Pet.STATE_CHICK_SMALL) {
            pet[iPet].pet.setImage(gameDesign.getGaCon128(), 25, 25);
        } else if (pet[iPet].state == Pet.STATE_CHICK_MEDIUM) {
            pet[iPet].pet.setImage(gameDesign.getGaTrungBinh128(), 40, 40);
        } else if (pet[iPet].state == Pet.STATE_CHICK_BIG) {
            pet[iPet].pet.setImage(gameDesign.getGaLon128(), 45, 45);
        }
        pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyseq);
        for (int i = 0; i < 5; i++) {
            petDoiThu1[i] = new Pet(new Sprite(gameDesign.getGaCon128(), 25, 25), infoDoithu[i % 5][0], infoDoithu[i % 5][1], infoDoithu[i % 5][2], infoDoithu[i % 5][3], infoDoithu[i % 5][4], infoDoithu[i % 5][5], infoDoithu[i % 5][6]);
        }
        setInfoDoiThu(1);
        for (int i = 5; i < 10; i++) {
            petDoiThu1[i] = new Pet(new Sprite(gameDesign.getGaTrungBinh128(), 40, 40), infoDoithu[i % 5][0], infoDoithu[i % 5][1], infoDoithu[i % 5][2], infoDoithu[i % 5][3], infoDoithu[i % 5][4], infoDoithu[i % 5][5], infoDoithu[i % 5][6]);
        }
        setInfoDoiThu(2);
        for (int i = 10; i < 15; i++) {
            petDoiThu1[i] = new Pet(new Sprite(gameDesign.getGaLon128(), 45, 45), infoDoithu[i % 5][0], infoDoithu[i % 5][1], infoDoithu[i % 5][2], infoDoithu[i % 5][3], infoDoithu[i % 5][4], infoDoithu[i % 5][5], infoDoithu[i % 5][6]);
        }
        setInfoDoiThu(3);
        for (int i = 15; i < 20; i++) {
            petDoiThu1[i] = new Pet(new Sprite(gameDesign.getGaLon128(), 45, 45), infoDoithu[i % 5][0], infoDoithu[i % 5][1], infoDoithu[i % 5][2], infoDoithu[i % 5][3], infoDoithu[i % 5][4], infoDoithu[i % 5][5], infoDoithu[i % 5][6]);
        }
        for (int i = 0; i < petDoiThu1.length; i++) {
            petDoiThu1[i].setPosition(xPetDoiThu1[i], yPetDoiThu1[i]);
        }
    }

    public void init() throws IOException {
        delay = 50;
        if (this.getWidth() >= 200) {
            topMainMenu = 250;
        } else {
            topMainMenu = this.getHeight() - 25 - font1.getHeight();
        }
        money = midlet.yourInfo.money;
        System.out.println(money);
        sMainMenu[0] = "Chăm sóc";
        if (this.getWidth() < 200) {
            sMainMenu[1] = "Thi đấu";
        } else {
            sMainMenu[1] = "Đi dạo";
        }
        sMainMenu[2] = "Cửa hàng";
        sMainMenu[3] = "Thông tin";
        sMainMenu[4] = "Gửi thú nuôi";
        sSubMenu1[0] = "Vệ sinh";
        sSubMenu1[1] = "Cho ăn";
        sSubMenu1[2] = "Học bài";
        sSubMenu1[3] = "Luyện tập";
        sSubMenu1[4] = "Y tế";
        sSubMenu2[0] = sSubMenu2[1] = sSubMenu2[2] = sSubMenu2[3] = "";
        sSubMenu3[0] = "Nạp 1000$";
        sSubMenu3[1] = "Mua thức ăn";
        sSubMenu3[2] = "Mua máu";
        sSubMenu3[3] = "Mua mana";
        nameArena[0] = "Núi đá cổ xưa";
        nameArena[1] = "Thung lũng tử thần";
        nameArena[2] = "Nam Cực";
        nameArena[3] = "Địa ngục môn";
        skillName = new String[10];
        indexPetChosen = 0;
        nextLevel[0] = nextLevel[1] = 90;
        numberSkill = 10;
        numberArena = 1;
        timeWaitChooseSkill = 10000;
        totalMemory = Runtime.getRuntime().totalMemory();
        if (this.getWidth() >= 200) {
            initSprite();
        } else {
            initSprite128();
        }
        initGameMedia();
        initChooseEggMap();
        initPetWhenStart();
//        if (iPet == 0) {
//            noBottleHP = petYoYo.infoPet1.noBottleHp;
//            noBottleMP = petYoYo.infoPet1.noBottleMP;
//        } else {
//            noBottleHP = petYoYo.infoPet2.noBottleHp;
//            noBottleMP = petYoYo.infoPet2.noBottleMP;
//        }
//        for (int i = 0; i < skillName.length; i++) {
//            skillName[i] = "Kĩ năng " + i;
//        }
        skillName[0] = "Kê trảo";
        skillName[1] = "Phi đao";
        skillName[2] = "Cầu lửa";
        skillName[3] = "Sóng âm";
        skillName[4] = "Động đất";
        skillName[5] = "Đóng băng";
        skillName[6] = "Phản đòn";
        skillName[7] = "Khiên băng";
        skillName[8] = "Tăng công";
        skillName[9] = "Tăng thủ";
        for (int i = 0; i < skilllv.length; i++) {
            if (iPet == 0) {
                skilllv[i] = midlet.infoPet1.skilllv[i];
            } else {
                skilllv[i] = midlet.infoPet2.skilllv[i];
            }
        }
        mana[0] = 0;
        mana[1] = 10;
        mana[2] = 20;
        mana[3] = 25;
        mana[4] = 50;
        mana[5] = 25;
        mana[6] = 80;
        mana[7] = 50;
        mana[8] = 75;
        mana[9] = 20;
        for (int i = 0; i < mana.length; i++) {
            mana[i] += (skilllv[i] - 1) * 5;
        }
        dam[0] = 3;
        dam[1] = 5;
        dam[2] = 7;
        dam[3] = 9;
        dam[4] = 11;
        dam[5] = 7;
        dam[6] = dam[7] = dam[8] = dam[9] = 0;
        for (int i = 0; i < 6; i++) {
            dam[i] += skilllv[i] - 1;
        }
        acc[0] = 100;
        acc[1] = 30;
        acc[2] = 30;
        acc[3] = 30;
        acc[4] = 30;
        acc[5] = 30;
        acc[6] = acc[7] = acc[8] = acc[9] = 0;
        for (int i = 1; i < 6; i++) {
            if (skilllv[i] == 2) {
                acc[i] = 50;
            } else if (skilllv[i] >= 3) {
                acc[i] = 100;
            }
        }
        for (int i = 0; i < costSkill.length; i++) {
            costSkill[i] = (i * 2 + 2) * 500 + 2 * skilllv[i] * 500;
        }
        for (int i = 0; i < spSkill.length; i++) {
            if (i <= 3) {
                spSkill[i] = 50 + 5 * 2 * (skilllv[i] - 1);
            } else if (i < 6) {
                spSkill[i] = 50 + 10 * 2 * (skilllv[i] - 1);
            } else {
                spSkill[i] = 50 + 15 * 2 * (skilllv[i] - 1);
            }
//            spSkill[i] = 1;
        }
        for (int i = 0; i < costUpInfo.length; i++) {
            costUpInfo[i] = 2000;
        }
        for (int i = 0; i < spUpInfo.length; i++) {
            spUpInfo[i] = 150;
        }
        for (int i = 0; i < noUpMyInfo.length; i++) {
            if (iPet == 0) {
                noUpMyInfo[i] = midlet.infoPet1.noUpMyInfo[i];
            } else {
                noUpMyInfo[i] = midlet.infoPet2.noUpMyInfo[i];
            }
        }
        costUpInfo[0] += 50 * noUpMyInfo[0];
        spUpInfo[0] += 15 * noUpMyInfo[0];
        costUpInfo[1] += 70 * noUpMyInfo[1];
        spUpInfo[1] += 25 * noUpMyInfo[1];
        costUpInfo[2] += 100 * noUpMyInfo[2];
        spUpInfo[2] += 15 * noUpMyInfo[2];
        costUpInfo[3] += 70 * noUpMyInfo[3];
        spUpInfo[3] += 20 * noUpMyInfo[3];
        if (iPet == 0) {
            isKeyBonus = midlet.infoPet1.isKeyBonus;
        } else {
            isKeyBonus = midlet.infoPet2.isKeyBonus;
        }
        levelUseSkill[0] = levelUseSkill[1] = levelUseSkill[2] = 2;
        levelUseSkill[3] = levelUseSkill[4] = levelUseSkill[5] = levelUseSkill[6] = levelUseSkill[7] = levelUseSkill[8] = levelUseSkill[9] = 2;
        isUseSkill[0] = isUseSkill[1] = isUseSkill[2] = true;
        isUseSkill[3] = isUseSkill[4] = isUseSkill[5] = isUseSkill[6] = isUseSkill[7] = isUseSkill[8] = isUseSkill[9] = true;
    }

    public void checkSystemTime() throws IOException {
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+7"));
        Date date = new Date();
        calendar.setTime(date);
        int date2 = calendar.get(Calendar.DATE);
        int hour2 = calendar.get(Calendar.HOUR);
        int min2 = calendar.get(Calendar.MINUTE);
        int date1 = midlet.infoPet1.date;
        int hour1 = midlet.infoPet1.hour;
        int min1 = midlet.infoPet1.min;
        if (iPet == 1) {
            date1 = midlet.infoPet2.date;
            hour1 = midlet.infoPet2.hour;
            min1 = midlet.infoPet2.min;
        }
        //Phai luu ca nextlevel nua!
        int expLoad = (date2 - date1) * 24 * 60 * 60 + (hour2 - hour1) * 60 * 60 + (min2 - min1) * 60;
        int expNextLevel = nextLevel[iPet];
        if (pet[iPet].exp + expLoad >= expNextLevel) {
            pet[iPet].level += 1;
            expLoad = 0;
//            nextLevel[iPet] = (pet[iPet].level + 1) * 10;
            if (pet[iPet].level < 10) {
                nextLevel[iPet] = 3 * (pet[iPet].level + 1) * 30;
            } else if (pet[iPet].level < 20) {
                nextLevel[iPet] = 4 * (pet[iPet].level + 1) * 45;
            } else if (pet[iPet].level < 30) {
                nextLevel[iPet] = 5 * (pet[iPet].level + 1) * 60;
            } else if (pet[iPet].level < 40) {
                nextLevel[iPet] = 6 * (pet[iPet].level + 1) * 100;
            } else if (pet[iPet].level < 50) {
                nextLevel[iPet] = 7 * (pet[iPet].level + 2) * 100;
            }
            if (pet[iPet].level >= 2) {
                pet[iPet].helthPoint = 0;
                pet[iPet].foodPoint = 0;
                pet[iPet].learnPoint = 0;
                pet[iPet].relaxPoint = 0;
            }
            pet[iPet].cleanPoint = 0;
            pet[iPet].foodPoint = 0;
            pet[iPet].mp += 10;
            pet[iPet].hp += 10;
            pet[iPet].attack += 1;
            pet[iPet].defend += 1;
            pet[iPet].cost += 50;
            isDrawAnouce = true;
            timeDrawAnouce = 0;
            pet[iPet].exp = expNextLevel;
            if (pet[iPet].getState() == Pet.STATE_EGG) {
                pet[iPet].setState(Pet.STATE_EGG_NUT, pet[iPet].chickEggNutseq);
                return;
            }
            if (pet[iPet].getState() == Pet.STATE_EGG_NUT) {
                bongEgg.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 14);
                if (totalMemory < 1000000 && this.getWidth() < 160) {
                    gameDesign.trungga128 = null;
                }
                if (this.getWidth() >= 200) {
                    pet[iPet].setImage(gameDesign.getGaCon(), 40, 40);
                } else {
                    pet[iPet].setImage(gameDesign.getGaCon128(), 25, 25);
                }
                pet[iPet].setState(Pet.STATE_CHICK_SMALL, pet[iPet].chickBabyseq);
                return;
            }
            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL && pet[iPet].level == LV_MEDIUM) {
                bongEgg.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 14);
                if (totalMemory < 1000000 && this.getWidth() < 160) {
                    gameDesign.trungga128 = null;
                }
                if (this.getWidth() >= 200) {
                    pet[iPet].setImage(gameDesign.getGaTrungBinh(), 60, 60);
                } else {
                    pet[iPet].setImage(gameDesign.getGaTrungBinh128(), 40, 40);
                }
                pet[iPet].setState(Pet.STATE_CHICK_MEDIUM, pet[iPet].chickMediumseq);
                return;
            }
            if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM && pet[iPet].level == LV_BIG) {
                if (totalMemory < 1000000 && this.getWidth() < 160) {
                    gameDesign.gaCon128 = null;
                }
                if (pet[iPet].level >= LV_BIG) {
                    if (this.getWidth() >= 200) {
                        pet[iPet].setImage(gameDesign.getGaLon(), 70, 70);
                        pet[iPet].setState(Pet.STATE_CHICK_BIG, pet[iPet].chickMediumseq);
                        bongEgg.setPosition(this.getWidth() / 2 - bongEgg.getWidth() / 2, bongEgg.getY());
//                        pet[iPet].setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, bongEgg.getY() - pet[iPet].pet.getHeight());
                    } else {
                        pet[iPet].setImage(gameDesign.getGaLon128(), 45, 45);
                        pet[iPet].setState(Pet.STATE_CHICK_BIG, pet[iPet].chickMediumseq);
                        bongEgg.setPosition(this.getWidth() / 2 - bongEgg.getWidth() / 2, bongEgg.getY());
                    }
                    return;
                }
            }
            if (pet[iPet].getState() == Pet.STATE_PHOENIX) {
                pet[iPet].helthPoint = 100;
                pet[iPet].foodPoint = 100;
                pet[iPet].learnPoint = 100;
                pet[iPet].relaxPoint = 100;
                pet[iPet].cleanPoint = 100;
            }
            for (int i = 0; i < isUseSkill.length; i++) {
                if (pet[iPet].level >= levelUseSkill[i]) {
                    isUseSkill[i] = true;
                }
            }
//            nextLevel[iPet] = (pet[iPet].level + 1) * 30;
            checkExpNextLevel(iPet);
        }
    }

    public void checkExpNextLevel(int iPet) {
        if (pet[iPet].level < 2) {
            nextLevel[iPet] = 3 * (pet[iPet].level + 1) * 30;
        } else if (pet[iPet].level < 9) {
            nextLevel[iPet] = 3 * (pet[iPet].level + 1) * 30;
        } else if (pet[iPet].level < 19) {
            nextLevel[iPet] = 4 * (pet[iPet].level + 1) * 45;
        } else if (pet[iPet].level < 29) {
            nextLevel[iPet] = 5 * (pet[iPet].level + 1) * 60;
        } else if (pet[iPet].level < 40) {
            nextLevel[iPet] = 6 * (pet[iPet].level + 1) * 100;
        } else if (pet[iPet].level < 50) {
            nextLevel[iPet] = 7 * (pet[iPet].level + 2) * 100;
        }
//        nextLevel[iPet] += 10;
    }

    public void run() {
        Graphics g = getGraphics();
//        while (isPlay) {
//            try {
//                if (!isPause && isStartedGame && !isExitPressed) {
//                    gamePlay();
//                    checkRunTime();
//                }
//                drawScreen(g);
//            } catch (Exception ex) {
//                ex.printStackTrace();
//            }
//            try {
//                Thread.sleep(delay);
//            } catch (Exception ex) {
//                ex.printStackTrace();
//            }
//            timeGc += delay;
//            if (timeGc >= 5000) {
//                Runtime.getRuntime().gc();
//                timeGc = 0;
//            }
//        }
        Thread currentThread = Thread.currentThread();
        while (currentThread == gameThread) {
            long startTime = System.currentTimeMillis();
            if (isShown()) {
                try {
                    if (!isPause && isStartedGame && !isExitPressed) {
                        gamePlay();
                        checkRunTime();
                    }
                    drawScreen(g);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                timeGc += delay;
                if (timeGc >= 5000) {
                    Runtime.getRuntime().gc();
                    timeGc = 0;
                }
            }
            long timeTake = System.currentTimeMillis() - startTime;
            if (timeTake < delay) {
                synchronized (this) {
                    try {
                        wait(delay - timeTake);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                }
            } else {
                Thread.currentThread().yield();
            }
        }
    }

    public void checkRunTime() {
        if (!isExitPressed && !isThiDau) {
            try {
                if (midlet.sound) {
                    if (gameMedia.getState() != gameMedia.STARTED) {
                        gameMedia.start();
                        gameMedia.setMediaTime(0);
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (!isExitPressed && !isThiDau && !isTrain) {
            time += delay;
            if (time >= 2000) {
                pet[iPet].subPoint();
                time = 0;
            }
        }
        if (!isExitPressed && isThiDau) {
            try {
                if (midlet.sound) {
                    if (fightMedia.getState() != fightMedia.STARTED) {
                        fightMedia.start();
                        fightMedia.setMediaTime(0);
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (isFinishChamsoc) {
            timeWaitChamsoc += delay;
        }
        if (pointer.isVisible() && !isStartWalk) {
            timePoinNhay += delay;
        }
        if (doctor.isVisible()) {
            timeDoctor += delay;
        }
        if (pet[iPet].state == Pet.STATE_EGG || pet[iPet].getState() == Pet.STATE_EGG_NUT || pet[iPet].getState() >= Pet.STATE_CHICK_SMALL) {
            if (!pet[iPet].isMove) {
                pet[iPet].timeAction += delay;
            }
        }
        if (pet[iPet].timeAction > 5000 && pet[iPet].timeAction <= 8000) {
            pet[iPet].timeJump += delay;
        }
        if (pet[iPet].timeAction > 8000) {
            pet[iPet].timeAction = 0;
            pet[iPet].timeJump = 0;
            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL || pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM || pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
                if (!pet[iPet].checkTired()) {
                    pet[iPet].isMove = true;
                    pet[iPet].isMoveLeft = true;
                    pet[iPet].noMove = 0;
                }
            }
        }
        if (isInfoScreen) {
            timeInfoNhay += delay;
        }
        if (isDrawAnouce) {
            timeDrawAnouce += delay;
        }
        if (isDrawTrainMiss) {
            timeTrainMiss += delay;
        }
        if (isDrawTrainFinish) {
            timeTrainFinish += delay;
        }
        if (!isThiDau && !isStartWalk) {
            pet[iPet].time += delay;
            if (!pet[iPet].checkTired()) {
                if (!pet[iPet].checkAddExp()) {
                    if (pet[iPet].time >= 1000) {
                        pet[iPet].time = 0;
                        pet[iPet].exp += 1;
                    }
                } else {
                    if (pet[iPet].time >= 2000) {
                        pet[iPet].time = 0;
                        pet[iPet].exp += 1;
                    }
                }
            }
        }
        if (isBeginFight) {
            if (timeDrawYourTurn <= 2000) {
                timeDrawYourTurn += delay;
            }
        }
        if (reHitting && !isTrailer) {
            if (timeWaitReHit <= 3000) {
                timeWaitReHit += delay;
                if (timeWaitReHit >= 1000) {
                    if (!isWin && !isLose) {
                        if (petDoiThu.mp <= mana[1]) {
                            if (doithuBottleMP > 0) {
                                petDoiThu.mp += 50;
                                doithuBottleMP--;
                                if (petDoiThu.mp > maxMPDoiThu) {
                                    petDoiThu.mp = maxMPDoiThu;
                                }
                            }
                        }
                        if (petDoiThu.hp < maxHPDoiThu / 2) {
                            if (doithuBottleHP > 0) {
                                petDoiThu.hp += 50;
                                doithuBottleHP--;
                                if (petDoiThu.hp > maxHPDoiThu) {
                                    petDoiThu.hp = maxHPDoiThu;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (isLose) {
            timeLose += delay;
        }
        if (isWin) {
            timeWin += delay;
        }
        if (isStartTrain) {
            timeStartTrain += delay;
        }
        if (isTrain && !isStartTrain) {
            if (timeTrain <= 0) {
                timeCoutTrain += delay;
            } else {
                timeTrain -= delay;
            }
            timeXTrain += delay;
        }
        if (!isInfoScreen && isDrPetThk1 && !isDrawAnouce && !isCleaning && !isLearning && !isDoctor) {
            timeDrawPetThink1 += delay;
        }
        if (isDrawNoCareClean || isDrawNoCareDoctor || isDrawNoCareEat || isDrawNoCareLearn || isDrawEmptyFood) {
            timeDrawNoCare += delay;
        }
        if (isTrailer) {
            if (this.getWidth() >= 200) {
                myHPLine.setVisible(false);
                myHpMp.setVisible(false);
                doithuHPline.setVisible(false);
                doithuHpMp.setVisible(false);
            }
            timeTrailer += delay;
            if (timeTrailer >= 2000) {
                timeTrailer = 0;
                isTrailer = false;
                if (this.getWidth() > 160) {
                    addNenFight.setVisible(false);
                }
                if (this.getWidth() >= 200) {
                    myHPLine.setVisible(true);
                    myHpMp.setVisible(true);
                    doithuHPline.setVisible(true);
                    doithuHpMp.setVisible(true);
                }
            }
        }
        if (isCanFight) {
            timeCanFight += delay;
            if (timeCanFight >= 1500) {
                isCanFight = false;
            }
        }
        if (isPresentItem) {
            timeDrawAnouceItem += delay;
            if (timeDrawAnouceItem >= 1500) {
                isPresentItem = false;
//                addMainScreen.fillCells(0, 0, 1, addMainScreen.getRows(), 0);
//                iAddMainScreen = 7;
                key.setVisible(false);
            }
        }
        if (isShockScreen) {
            timeShock += delay;
        }
        if (isSavePetSuccess) {
            timeSavePet += delay;
            if (timeSavePet >= 1500) {
                isSavePetSuccess = false;
            }
        }
        if (isHitSkill2) {
            timeHitSkill2 += delay;
        }
        if (isWaitHit6) {
            timeHitSkill6 += delay;
        }
        if (isWaitReHit6) {
            timeReHit6 += delay;
        }
        if (isReHit2) {
            timeReHit2 += delay;
        }
        if (!isTrailer && isYourTurn && !isHitting && isBeginFight) {
            timeWaitChooseSkill -= delay;
        }
        if (!isTrailer && !isHitting && isBeginFight) {
            time1kChooseSkill += delay;
        }
        if (isNotEnoughMoneyBuyFood) {
            timeDrawNotEnoughMoney += delay;
            if (timeDrawNotEnoughMoney > 1500) {
                isNotEnoughMoneyBuyFood = false;
                timeDrawNotEnoughMoney = 0;
            }
        }
        if (isLoadingWalk) {
            timeLoadingWalk += delay;
            if (timeLoadingWalk >= 1000) {
                timeLoadingWalk = 0;
                isLoadingWalk = false;
                isStartWalk = true;
                pet[iPet].pet.setTransform(Sprite.TRANS_MIRROR);
                pet[iPet].setPosition(5, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
                pet[iPet].pet.setFrame(30);
                curX = 0;
                initWalkingMap();
            }
        }
    }

    public void inputPetWalk() {
        int keyState = getKeyStates();
        if ((keyState & GameCanvas.RIGHT_PRESSED) != 0) {
            if (this.lastDirection != RIGHT) {
                this.lastDirection = RIGHT;
                int x = pet[iPet].getX();
                int y = pet[iPet].getY();
                pet[iPet].pet.setTransform(Sprite.TRANS_MIRROR);
                pet[iPet].setPosition(x, y);
            }
            checkInput2();
            if (pet[iPet].getX() + pet[iPet].pet.getWidth() + 5 < parkWidth) {
                if (checkInputWaterRIGHT()) {
                    if (isInPutMove && prevDirect != RIGHT) {
                        if (isInputMoveCautruot && prevCauTruot != RIGHT) {
                            pet[iPet].pet.move(4, 0);
                        }
                    }
                }
            }
            pet[iPet].chickMove();
            adjustViewPort(curX + 4, 0);
        } else if ((keyState & GameCanvas.LEFT_PRESSED) != 0) {
            if (this.lastDirection != LEFT) {
                this.lastDirection = LEFT;
                int x = pet[iPet].getX();
                int y = pet[iPet].getY();
                pet[iPet].pet.setTransform(Sprite.TRANS_NONE);
                pet[iPet].setPosition(x, y);
            }
            checkInput2();
            if (pet[iPet].getX() - 5 > 0) {
                if (checkInputWaterLEFT()) {
                    if (isInPutMove && prevDirect != LEFT) {
                        if (isInputMoveCautruot && prevCauTruot != LEFT) {
                            pet[iPet].pet.move(-4, 0);
                        }
                    }
                }
            }
            pet[iPet].chickMove();
            adjustViewPort(curX - 4, 0);
        } else if ((keyState & GameCanvas.UP_PRESSED) != 0) {
            if (this.lastDirection != UP) {
                this.lastDirection = UP;
            }
            checkInput2();
            if (pet[iPet].getY() - 4 > park.getY()) {
                if (isInPutMove && prevDirect != UP) {
                    if (isInputMoveCautruot && prevCauTruot != UP) {
                        pet[iPet].pet.move(0, -4);
                    }
                }
            }
//            for (int i = 0; i < petDoiThu1.length; i++) {
//                if (pet[iPet].pet.collidesWith(petDoiThu1[i].pet, true)) {
//                    isCollidesPet = true;
//                    iChooseFight = i;
//                }
//            }
            pet[iPet].chickMove();
        } else if ((keyState & GameCanvas.DOWN_PRESSED) != 0) {
            if (this.lastDirection != DOWN) {
                this.lastDirection = DOWN;
            }
            checkInput2();
            if (pet[iPet].getY() + pet[iPet].pet.getHeight() + 3 < this.getHeight()) {
                if (checkInputWaterDOWN()) {
                    if (isInPutMove && prevDirect != DOWN) {
                        if (isInputMoveCautruot && prevCauTruot != DOWN) {
                            pet[iPet].pet.move(0, 4);
                        }
                    }
                }
            }
            pet[iPet].chickMove();
        } else {
            pet[iPet].pet.setFrame(30);
        }
    }

    public void adjustViewPort(int x, int y) {
        int sx = pet[iPet].getX();
        int sy = pet[iPet].getY();
        int xmin = this.curX + /*this.human.sprite.getWidth()*/ MIN_BUFFER;
        int xmax = this.curX + this.getWidth() - this.pet[iPet].pet.getWidth() - MIN_BUFFER;
//        int ymin = this.curY + 2 * landWidth +/*this.human.sprite.getHeight()*/ MIN_BUFFER;
//        int ymax = this.curY + this.getHeight() - this.human.sprite.getHeight() - bien.getHeight() - MIN_BUFFER;
        if (sx >= xmin && sx <= xmax /*&& sy >= ymin && sy <= ymax*/) {
            return;
        }
        if (this.lastDirection == LEFT && sx >= xmin) {
            return;
        }
        if (this.lastDirection == RIGHT && sx <= xmax) {
            return;
        }
//        if (this.lastDirection == UP && sy >= ymin) {
//            return;
//        }
//        if (this.lastDirection == DOWN && sy <= ymax) {
//            return;
//        }
        if (x < 0) {
            this.curX = 0;
        } else if (x > glass.getWidth() - this.getWidth()) {
            this.curX = glass.getWidth() - this.getWidth();
        } else {
            this.curX = x;
        }
//        if (y < 0) {
//            this.curY = 0;
//        } else if (y > bgHeight - this.getHeight()) {
//            this.curY = bgHeight - this.getHeight();
//        } else {
//            this.curY = y;
//        }
    }

    public void gamePlay() {
        if (isStartWalk) {
            inputPetWalk();
        } else {
            if (pet[iPet].level < 2 || pet[iPet].getState() == Pet.STATE_PHOENIX) {
                pet[iPet].helthPoint = 100;
                pet[iPet].relaxPoint = 100;
                pet[iPet].learnPoint = 100;
                pet[iPet].foodPoint = 100;
            }
            if (pet[iPet].getState() == Pet.STATE_PHOENIX) {
                pet[iPet].cleanPoint = 100;
                thinking.setVisible(false);
                iconThinking.setVisible(false);
            }
            isWork = isThiDau || isTrain || isStartWalk;
            isChamsoc = isCleaning || isLearning || isDoctor;
            pointerMove();
            setLevelPet();
            if (!isThiDau && !isInfoScreen) {
                petAct();
            }
            if (pet[iPet].getState() == Pet.STATE_EGG || pet[iPet].getState() == Pet.STATE_EGG_NUT) {
                if (this.getWidth() >= 200) {
                    bongEgg.setPosition(pet[iPet].pet.getX() - 6, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 14);
                } else {
                    bongEgg.setPosition(pet[iPet].pet.getX() - 3, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 10);
                }
            } else if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                if (this.getWidth() >= 200) {
                    bongEgg.setPosition(pet[iPet].pet.getX(), pet[iPet].getY() + 14 + (pet[iPet].pet.getHeight() - 40));
                } else {
                    bongEgg.setPosition(pet[iPet].pet.getX() + 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 10);
                }
            } else if (pet[iPet].getState() > Pet.STATE_CHICK_SMALL) {
                if (this.getWidth() >= 200) {
                    bongEgg.setPosition(pet[iPet].pet.getX() + 7, pet[iPet].getY() + 17 + (pet[iPet].pet.getHeight() - 40));
                } else {
                    bongEgg.setPosition(pet[iPet].pet.getX() + 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 10);
                }
            }
            if (pet[iPet].getState() == Pet.STATE_PHOENIX) {
                bongEgg.setVisible(false);
            }
            if (!isThiDau && !isTrain) {
                checkThinking();
            }
            if (isCleaning) {
                clean();
            }
            if (isDoctor) {
                doctor();
            }
            if (isLearning) {
                learn();
            }
            if (isEating) {
                eat();
            }
            bongEgg.setVisible(pet[iPet].pet.isVisible());
//            pet[iPet].skillPoint = 100;
        }
    }

    public void drawScreen(Graphics g) {
        if (isStartedGame) {
            if (!isStartWalk) {
                if (!isWork) {
                    if (isInfoScreen) {
                        if (this.getWidth() >= 200) {
                            drawInfoScreen(g);
                        } else {
                            drawInfoScreen128(g);
                        }
                    } else {
                        drawMainScreen(g);
                    }
                } else {
                    if (isTrain) {
                        drawTrainScreen(g);
                    } else if (isThiDau) {
                        if (isMenuFight) {
                            drawFightScreenMenu(g);
                        }
//                        if (isInfoFight) {
//                            drawInfoFight(g);
//                        }
//                        if (isDrawSkillFight) {
//                            drawSkillFight(g);
//                        }
                        if (isChooseFight) {
                            drawChooseFight(g);
                        }
                        if (isDrawInfoDoiThu) {
                            drawInfoDoiThu(g);
                        }
                        if (isBeginFight) {
                            drawFight(g);
                        }
                        if (isChooseArena) {
                            drawChooseArena(g);
                        }
                    }
                }
            } else {
                drawPark(g);
            }
        } else {
            if (!isChooseEgg) {
                if (this.getWidth() >= 200) {
                    drawChoosePet(g);
                } else {
                    drawChoosePet128(g);
                }
            } else {
                drawChooseEgg(g);
            }
        }
    }

    public void drawMainScreen(Graphics g) {
//        System.out.println(petYoYo.infoPet2.skilllv[0]);
        g.setFont(font1);
        g.setColor(0x00ff00);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        g.setColor(0xffffff);
        lm.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lm.paint(g, 0, 0);
        mainMenuActive(g);
        if (iMainMenu == 0) {
            subMenuActive(g, subMenu1, sSubMenu1, iSubMenu1);
        }
        if (iMainMenu == 2) {
            subMenuActive(g, subMenu3, sSubMenu3, iSubMenu3);
        }
//        g.setColor(0x0000ff);
//        g.drawString(Runtime.getRuntime().freeMemory() + "B", this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
        g.setColor(0xffffff);
        if (isPointMenuRightPressed) {
            g.setColor(0xffff00);
            g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 3 * font3.getHeight() / 2, font3.stringWidth("Trở về") + 5, 3 * font3.getHeight() / 2);
        }
        g.setColor(1, 80, 126);
        if (this.getWidth() >= 200) {
            g.setFont(font3);
        } else {
            g.setFont(font1);
        }
        g.drawString("Tiền :" + money + "$", 0, 0, Graphics.LEFT | Graphics.TOP);
        if (!isExitPressed && !isSavePetMss) {
            if (!isOpenSubMenu && !isLock) {
                g.drawString("Đóng", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
            }
            if (!isOpenSubMenu && isLock) {
                g.drawString("Mở", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
            }
            if (!isOpenSubMenu && !isMainBeginDown && !isMainBeginUp && !isSubBeginLeft && !isSubBeginRight) {
                g.drawString("Thoát", 0, this.getHeight(), Graphics.LEFT | Graphics.BOTTOM);
            }
        } else {
            g.setColor(0, 128, 192);
            g.fillRect(0, this.getHeight() - 3 * font1.getHeight() / 2, this.getWidth(), 3 * font1.getHeight() / 2);
            if (isPointerMenuLeftPressed) {
                g.setColor(0xffff00);
                g.fillRoundRect(0, this.getHeight() - 3 * font3.getHeight() / 2, font3.stringWidth("Đồng ý") + 5, 3 * font3.getHeight() / 2, 5, 5);
            }
            if (isPointMenuRightPressed) {
                g.setColor(0xffff00);
                g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 3 * font3.getHeight() / 2, font3.stringWidth("Trở về") + 5, 3 * font3.getHeight() / 2);
            }
            g.setColor(0xffffff);
            g.drawString("Đồng ý", 0, this.getHeight(), Graphics.LEFT | Graphics.BOTTOM);
            g.drawString("Bỏ qua", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
        }
        if (isOpenSubMenu) {
            g.drawString("Menu", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
        }
//        String sTime = petYoYo.infoPet1.isChosenPet + "," + petYoYo.infoPet1.date + "," + petYoYo.infoPet1.hour + "," + petYoYo.infoPet1.min;
//        g.drawString(sTime, 0, 0, Graphics.LEFT | Graphics.TOP);
        if (isDrawAnouce) {
            drawAnnouncement(g);
        } else {
            if (isDrPetThk1 && !isCleaning && !isLearning && !isDoctor && !isTrain && !isEating && !isLoadingWalk) {
                drawPetThink1(g);
                if (timeDrawPetThink1 >= 2000) {
                    isDrPetThk1 = false;
                    timeDrawPetThink1 = 0;
                }
            }
            if (!isDrPetThk1 && !isCleaning && !isLearning && !isDoctor && !isTrain) {
                if (isDrawNoCareClean || isDrawNoCareDoctor || isDrawNoCareEat || isDrawNoCareLearn || isDrawEmptyFood) {
                    if (timeDrawNoCare < 1500) {
                        drawNoCare(g);
                    } else {
                        pointer.setVisible(true);
                        pet[iPet].pet.setVisible(true);
                        face.setVisible(false);
                        face.setFrameSequence(gameDesign.faceseq001);
                        isDrawNoCareClean = isDrawNoCareDoctor = isDrawNoCareEat = isDrawNoCareLearn = isDrawEmptyFood = false;
                    }
                }
            }
        }
        if (!isLoadingWalk) {
            if (isCleaning || isLearning || isDoctor || isEating) {
                if (!isFinishChamsoc) {
                    drawPetThink(g);
                }
            }
            if (isFinishChamsoc) {
                drawPetFinishChamsoc(g);
            }
            if (isSavePetMss) {
                drawMessageSavePet(g);
            } else {
                if (isSavePetSuccess) {
                    drawSavePetSuccess(g);
                }
            }
            if (isExitPressed) {
                drawMessageBox(g);
            }
            if (isCanFight) {
                drawCanFight(g);
            }
            if (isPresentItem) {
                drawAnouceItem(g);
            }
        } else {
            drawLoadingWalk(g);
        }
        if (isOpenSubMenu) {
            if (iMainMenu == 2) {
                g.setColor(0xff0000);
                if (iSubMenu3 == 1) {
                    g.drawString("Giá : 200$", this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                }
                if (iSubMenu3 == 2) {
                    g.drawString("400$/1 bình", this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                }
                if (iSubMenu3 == 3) {
                    g.drawString("500$/1 bình", this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                }
            }
        }
        if (isBuyFood || isBuyHP || isBuyMP) {
            g.setFont(font3);
            g.setColor(0xff0000);
            if (isBuyFood) {
                g.drawString("-" + 200 + "$", font1.stringWidth("Tiền: "), font1.getHeight() + 5, Graphics.TOP | Graphics.LEFT);
                g.drawString("+1 thức ăn", this.getWidth() / 2, yNotEnoughMoney, Graphics.BOTTOM | Graphics.HCENTER);
            }
            if (isBuyHP) {
                g.drawString("-" + 400 + "$", font1.stringWidth("Tiền: "), font1.getHeight() + 5, Graphics.TOP | Graphics.LEFT);
                g.drawString("+1 bình HP", this.getWidth() / 2, yNotEnoughMoney, Graphics.BOTTOM | Graphics.HCENTER);
            }
            if (isBuyMP) {
                g.drawString("-" + 500 + "$", font1.stringWidth("Tiền: "), font1.getHeight() + 5, Graphics.TOP | Graphics.LEFT);
                g.drawString("+1 bình MP", this.getWidth() / 2, yNotEnoughMoney, Graphics.BOTTOM | Graphics.HCENTER);
            }
            if (yNotEnoughMoney > pet[iPet].getY() - 15) {
                yNotEnoughMoney -= 5;
            } else {
                isBuyFood = false;
                isBuyHP = false;
                isBuyMP = false;
                yNotEnoughMoney = pet[iPet].getY();
            }
        }
        flushGraphics();
    }

    public void drawPark(Graphics g) {
        try {
//            g.drawImage(gameDesign.getPark(), 0, 0, 0);
            lmPark.setViewWindow(curX, 0, this.getWidth(), this.getHeight());
            lmPark.paint(g, 0, 0);
            for (int i = 0; i < petDoiThu1.length; i++) {
                petDoiThu1[i].pet.nextFrame();
            }
            if (isCollidesPet) {
                g.setColor(0x0000ff);
                g.fillRect(0, this.getHeight() - 3 * font1.getHeight() / 2, this.getWidth(), 3 * font1.getHeight() / 2);
            }
            if (isCollidesPet) {
                g.setColor(0xffffff);
                g.drawString("Thi đấu", this.getWidth() / 2, this.getHeight(), Graphics.BOTTOM | Graphics.HCENTER);
//                g.drawString("Thông tin", 0, this.getHeight(), Graphics.LEFT | Graphics.BOTTOM);
            }
            g.setFont(font1);
            if (!isExitWalk) {
                if (!isCollidesPet) {
                    g.setColor(1, 80, 126);
                } else {
                    g.setColor(0xffffff);
                }
                g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            } else {
                g.setColor(0x0000ff);
                g.fillRect(0, this.getHeight() - 3 * font1.getHeight() / 2, this.getWidth(), 3 * font1.getHeight() / 2);
                g.drawString("Bạn có muốn thoát ?", this.getWidth() / 2, this.getHeight() - 2 * font1.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
                g.setColor(0xffffff);
                g.drawString("Đồng ý", 0, this.getHeight(), Graphics.BOTTOM | Graphics.LEFT);
                g.drawString("Bỏ qua", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            }
            for (int i = 0; i < petDoiThu1.length; i++) {
                String str = "Lv " + petDoiThu1[i].level;
                int strW = font1.stringWidth(str);
                if (!isDoiThuLose[i]) {
                    g.setColor(0xffffff);
                } else {
                    g.setColor(0xff0000);
                }
                g.fillRect(petDoiThu1[i].getX() + petDoiThu1[i].pet.getWidth() / 2 - strW / 2 - 3 - curX, petDoiThu1[i].getY() - font1.getHeight() - 4, strW + 6, font1.getHeight() + 4);
                g.setColor(0x000000);
                g.drawRect(petDoiThu1[i].getX() + petDoiThu1[i].pet.getWidth() / 2 - strW / 2 - 3 - curX, petDoiThu1[i].getY() - font1.getHeight() - 4, strW + 6, font1.getHeight() + 4);
                g.drawString(str, petDoiThu1[i].getX() + petDoiThu1[i].pet.getWidth() / 2 - curX, petDoiThu1[i].getY() - font1.getHeight() - 2, Graphics.TOP | Graphics.HCENTER);
            }
            flushGraphics();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void drawLoadingWalk(Graphics g) {
        g.setColor(0x0000ff);
        g.fillRect(0, this.getHeight() - 3 * font1.getHeight() / 2, this.getWidth(), this.getHeight());
        g.setColor(0xffffff);
        g.setFont(font1);
        g.drawString("Loading...", this.getWidth() / 2, this.getHeight() - font1.getHeight() / 4, Graphics.BOTTOM | Graphics.HCENTER);
        String str1 = "Đi chơi ! Đi chơi !";
        g.setFont(font1);
        g.setColor(230, 225, 153);
        g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 3 * font1.getHeight() / 2, 5, 5);
        g.setColor(112, 142, 142);
        g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
        g.setColor(0x000000);
        g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
        flushGraphics();
    }

    public void drawAnouceItem(Graphics g) {
        key.setPosition(this.getWidth() / 2 - key.getWidth() / 2, 5 + font2.getHeight() + key.getHeight());
        if (this.getWidth() > 160) {
            addMainScreen.setVisible(true);
            if (iAddMainScreen >= 0) {
                addMainScreen.setCell(0, iAddMainScreen, 1);
                addMainScreen.setCell(0, 15 - iAddMainScreen, 1);
                if (iAddMainScreen > 0) {
                    iAddMainScreen--;
                }
            }
        } else {
            iAddMainScreen = 0;
            g.setColor(0x000000);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
        }
        if (iAddMainScreen == 0) {
            key.setVisible(true);
        }
        lmAnouceItem.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lmAnouceItem.paint(g, 0, 0);
        if (iAddMainScreen == 0) {
            g.setColor(0xffffff);
            g.setFont(font2);
            g.drawString("Quà tặng", this.getWidth() / 2, 5, Graphics.HCENTER | Graphics.TOP);
            g.setFont(font1);
            g.drawString("Chìa khóa đấu trường 1", this.getWidth() / 2, key.getY() + key.getHeight() + 5, Graphics.TOP | Graphics.HCENTER);
            g.drawString("Thú nuôi đã có thể thi đấu", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Chiến thắng ở đấu trường 1", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("bạn sẽ có chìa khóa đấu trường 2", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        }
    }

    public void drawAnouceFight(Graphics g) {
        face.setPosition(this.getWidth() / 2 - face.getWidth() / 2, 5 + font2.getHeight() + 5);
        face.nextFrame();
        key.setPosition(this.getWidth() / 2 - key.getWidth() / 2, face.getY() + face.getHeight() + 5);
        if (this.getWidth() > 160) {
            addMainScreen.setVisible(true);
            if (iAddMainScreen >= 0) {
                addMainScreen.setCell(0, iAddMainScreen, 1);
                addMainScreen.setCell(0, 15 - iAddMainScreen, 1);
                if (iAddMainScreen > 0) {
                    iAddMainScreen--;
                }
            }
        } else {
            iAddMainScreen = 0;
            g.setColor(0x000000);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
        }
        if (iAddMainScreen == 0) {
            face.setVisible(true);
            key.setVisible(isPresentKey);
        }
        lmAnouceItem.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lmAnouceItem.paint(g, 0, 0);
        g.setColor(0xffffff);
        g.setFont(font2);
        if (iAddMainScreen == 0) {
            if (isWin) {
                g.drawString("Thắng rồi !", this.getWidth() / 2, 5, Graphics.HCENTER | Graphics.TOP);
            }
            if (isLose) {
                g.drawString("Thua rồi !", this.getWidth() / 2, 5, Graphics.HCENTER | Graphics.TOP);
            }
            if (isPresentKey) {
                g.setFont(font1);
                g.drawString("Chìa khóa đấu trường " + (key.getFrame() + 1), this.getWidth() / 2, key.getY() + key.getHeight() + 5, Graphics.TOP | Graphics.HCENTER);
            }
            if (this.getWidth() < 200) {
                if (isWin) {
                    g.drawString("Thắng : " + infoDoithu[iChooseFight][6] + "$", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                } else if (isLose) {
                    g.drawString("Thua : " + infoDoithu[iChooseFight][6] + "$", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                }
            } else {
                if (isWin) {
                    g.drawString("Thắng : " + petDoiThu.cost + "$", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                } else if (isLose) {
                    g.drawString("Thua : " + petDoiThu.cost + "$", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                }
            }
            if (this.getWidth() < 200) {
                if (isWin) {
                    g.drawString("+" + infoDoithu[iChooseFight][3] + " sp", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + 2 * font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                } else if (isLose) {
                    g.drawString("-" + infoDoithu[iChooseFight][3] + " sp", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + 2 * font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                }
            } else {
                if (isWin) {
                    g.drawString("+" + petDoiThu.skillPoint + " sp", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + 2 * font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                } else if (isLose) {
                    g.drawString("-5sp", this.getWidth() / 2, key.getY() + key.getHeight() + 5 + 2 * font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
                }
            }
        }
    }

    public void drawMessageBox(Graphics g) {
        fillRectPointerPressed(g);
        String title1 = "", title2 = "", ok = "Đồng ý", cancel = "Bỏ qua";
        g.setColor(0, 128, 192);
        g.setFont(font1);
        if (isExitPressed) {
            if (isSavedPet) {
                title1 = "Bạn có muốn thoát game ?";
            } else {
                title1 = "Bạn chưa gửi thú cưng !!!";
                title2 = "Bạn có muốn thoát game ?";
            }
        }
        g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(title1) / 2 - 10, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2, font1.stringWidth(title1) + 20, (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2), 5, 5);
        g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(title1) / 2 - 10 - 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 - 2, font1.stringWidth(title1) + 20 + 3, (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) + 3, 5, 5);
        g.setColor(0xffffff);
        g.drawString(title1, this.getWidth() / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5, Graphics.TOP | Graphics.HCENTER);
        g.drawString(title2, this.getWidth() / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
        int off = font1.stringWidth(cancel) + 6;
        g.drawString(ok, this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 - font1.stringWidth(ok) / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5 + font1.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
        g.drawString(cancel, this.getWidth() / 2 + font1.stringWidth(title1) / 4 - font1.stringWidth(cancel) / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5 + font1.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
        g.setColor(0x0000ff);
        if (isOKMssB) {
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 - off / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5, off, 3 * font1.getHeight() / 2, 5, 5);
        } else {
            g.drawRoundRect(this.getWidth() / 2 + font1.stringWidth(title1) / 4 - off / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5, off, 3 * font1.getHeight() / 2, 5, 5);
        }
    }

    public void drawMessageSavePet(Graphics g) {
        int cost;
        if (pet[iPet].level < 2) {
            cost = 100;
        } else if (pet[iPet].level < 10) {
            cost = 200;
        } else if (pet[iPet].level < 20) {
            cost = 350;
        } else {
            cost = 550;
        }
        moneySavePet = cost;
        fillRectPointerPressed(g);
        String title1 = "", title2 = "", ok = "Đồng ý", cancel = "Bỏ qua";
        g.setColor(0, 128, 192);
        g.setFont(font1);
        if (isSavePetMss) {
            title1 = "Bạn sẽ tốn " + cost + "$ cho dịch vụ";
            title2 = "Bạn có muốn thực hiện";
        }
        g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(title1) / 2 - 10, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2, font1.stringWidth(title1) + 20, (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2), 5, 5);
        g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(title1) / 2 - 10 - 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 - 2, font1.stringWidth(title1) + 20 + 3, (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) + 3, 5, 5);
        g.setColor(0xffffff);
        g.drawString(title1, this.getWidth() / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5, Graphics.TOP | Graphics.HCENTER);
        g.drawString(title2, this.getWidth() / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
        int off = font1.stringWidth(cancel) + 6;
        g.drawString(ok, this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 - font1.stringWidth(ok) / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5 + font1.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
        g.drawString(cancel, this.getWidth() / 2 + font1.stringWidth(title1) / 4 - font1.stringWidth(cancel) / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5 + font1.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
        g.setColor(0x0000ff);
        if (isOKSavePet) {
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 - off / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5, off, 3 * font1.getHeight() / 2, 5, 5);
        } else {
            g.drawRoundRect(this.getWidth() / 2 + font1.stringWidth(title1) / 4 - off / 2, this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5, off, 3 * font1.getHeight() / 2, 5, 5);
        }
    }

    public void drawInfoScreen(Graphics g) {
        if (iInfo == 0) {
            key.setVisible(false);
            pet[iPet].pet.setVisible(false);
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(true);
                infoLine[i].setVisible(true);
            }
            if (xInfo < this.getWidth() / 2) {
                xInfo += this.getWidth() / 6;
            } else {
                xInfo = this.getWidth() / 2;
            }
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(1, 80, 126);
            if (this.getWidth() >= 200) {
                g.setFont(font2);
                g.fillRoundRect(xInfo - (font2.stringWidth("Tình trạng thú nuôi") + 10) / 2, 5, font2.stringWidth("Tình trạng thú nuôi") + 10, 3 * font2.getHeight() / 2, 5, 5);
            }
            g.setColor(0xffffff);
            if (this.getWidth() >= 200) {
                g.drawString("Tình trạng thú nuôi", xInfo, 5 + font2.getHeight() / 4, Graphics.TOP | Graphics.HCENTER);
            } else {
                g.drawString("Tình trạng thú nuôi", xInfo, 0, Graphics.TOP | Graphics.HCENTER);
            }
            int dxTitle = 3 * subMenu1[0].getHeight() / 2;
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setPosition(xInfo - this.getWidth() / 3 + 3, dxTitle + i * (subMenu1[i].getWidth() + 5));
                g.setColor(1, 80, 126);
                g.fillRoundRect(xInfo - this.getWidth() / 3, dxTitle + i * (subMenu1[i].getWidth() + 5), 2 * this.getWidth() / 3, subMenu1[i].getHeight(), 10, 10);
                g.setFont(font3);
                g.setColor(0xffffff);
                g.drawString(sSubMenu1[i], xInfo - this.getWidth() / 3 + subMenu1[i].getWidth() + 5, dxTitle + i * (subMenu1[i].getWidth() + 5), Graphics.TOP | Graphics.LEFT);
                infoLine[i].setPosition(subMenu1[i].getX() + subMenu1[i].getWidth() + 5, subMenu1[i].getY() + font1.getHeight() + 5);
            }
            g.drawString(pet[iPet].cleanPoint + "%", xInfo + this.getWidth() / 3 - 5, dxTitle + 0 * (subMenu1[0].getWidth() + 5) /*+ font1.getHeight()*/, Graphics.RIGHT | Graphics.TOP);
            g.drawString(pet[iPet].foodPoint + "%", xInfo + this.getWidth() / 3 - 5, dxTitle + 1 * (subMenu1[0].getWidth() + 5) /*+ font1.getHeight()*/, Graphics.RIGHT | Graphics.TOP);
            g.drawString(pet[iPet].learnPoint + "%", xInfo + this.getWidth() / 3 - 5, dxTitle + 2 * (subMenu1[0].getWidth() + 5) /*+ font1.getHeight()*/, Graphics.RIGHT | Graphics.TOP);
            g.drawString(pet[iPet].relaxPoint + "%", xInfo + this.getWidth() / 3 - 5, dxTitle + 3 * (subMenu1[0].getWidth() + 5) /*+ font1.getHeight()*/, Graphics.RIGHT | Graphics.TOP);
            g.drawString(pet[iPet].helthPoint + "%", xInfo + this.getWidth() / 3 - 5, dxTitle + 4 * (subMenu1[0].getWidth() + 5) /*+ font1.getHeight()*/, Graphics.RIGHT | Graphics.TOP);
            int xWidth = infoLine[0].getWidth() * pet[iPet].cleanPoint / 100;
            if (xWidth >= 60) {
                g.setColor(0x00ff00);
            } else if (xWidth >= 30) {
                g.setColor(0xffff00);
            } else {
                g.setColor(0xff0000);
            }
            g.fillRect(infoLine[0].getX() + 1, infoLine[0].getY() + 1, xWidth, infoLine[0].getHeight() - 2);
            xWidth = infoLine[1].getWidth() * pet[iPet].foodPoint / 100;
            if (xWidth >= 60) {
                g.setColor(0x00ff00);
            } else if (xWidth >= 30) {
                g.setColor(0xffff00);
            } else {
                g.setColor(0xff0000);
            }
            g.fillRect(infoLine[1].getX() + 1, infoLine[1].getY() + 1, xWidth, infoLine[1].getHeight() - 2);
            xWidth = infoLine[2].getWidth() * pet[iPet].learnPoint / 100;
            if (xWidth >= 60) {
                g.setColor(0x00ff00);
            } else if (xWidth >= 30) {
                g.setColor(0xffff00);
            } else {
                g.setColor(0xff0000);
            }
            g.fillRect(infoLine[2].getX() + 1, infoLine[2].getY() + 1, xWidth, infoLine[2].getHeight() - 2);
            xWidth = infoLine[3].getWidth() * pet[iPet].relaxPoint / 100;
            if (xWidth >= 60) {
                g.setColor(0x00ff00);
            } else if (xWidth >= 30) {
                g.setColor(0xffff00);
            } else {
                g.setColor(0xff0000);
            }
            g.fillRect(infoLine[3].getX() + 1, infoLine[3].getY() + 1, xWidth, infoLine[3].getHeight() - 2);
            xWidth = infoLine[4].getWidth() * pet[iPet].helthPoint / 100;
            if (xWidth >= 60) {
                g.setColor(0x00ff00);
            } else if (xWidth >= 30) {
                g.setColor(0xffff00);
            } else {
                g.setColor(0xff0000);
            }
            g.fillRect(infoLine[4].getX() + 1, infoLine[4].getY() + 1, xWidth, infoLine[4].getHeight() - 2);
            if (isPointMenuRightPressed) {
                g.setColor(0xffff00);
                g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 2 * font3.getHeight(), font3.stringWidth("Trở về") + 5, 2 * font3.getHeight());
            }
            g.setColor(0xffffff);
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            if (isPointInfoLeftPress) {
                g.setColor(0xffff00);
                g.fillRect(arrowInfo1.getX(), arrowInfo1.getY() - 3, arrowInfo1.getWidth() + 5, arrowInfo1.getHeight() + 6);
            }
            if (isPointInfoRightPress) {
                g.setColor(0xffff00);
                g.fillRect(arrowInfo2.getX() - 5, arrowInfo2.getY() - 3, arrowInfo2.getWidth() + 5, arrowInfo2.getHeight() + 6);
            }
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        } else if (iInfo == 1) {
            key.setVisible(false);
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            if (xState < this.getWidth() / 2) {
                xState += this.getWidth() / 6;
            } else {
                xState = this.getWidth() / 2;
            }
            pet[iPet].pet.setVisible(true);
            pet[iPet].pet.setPosition(xState - pet[iPet].pet.getWidth() / 2, 10 + 3 * font2.getHeight() / 2);
            if (pet[iPet].level >= 2) {
                pet[iPet].chickMove();
            }
            g.setFont(font2);
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(1, 80, 126);
            g.fillRoundRect(xState - (font2.stringWidth("Giai đoạn phát triển") + 10) / 2, 5, font2.stringWidth("Giai đoạn phát triển") + 10, 3 * font2.getHeight() / 2, 5, 5);
            g.setColor(0xffffff);
            g.drawString("Giai đoạn phát triển", xState, 5 + font2.getHeight() / 4, Graphics.TOP | Graphics.HCENTER);
            if (pet[iPet].getName() == Pet.CHICK) {
                g.setFont(font1);
                if (pet[iPet].getState() == Pet.STATE_EGG || pet[iPet].getState() == Pet.STATE_EGG_NUT) {
                    g.setColor(1, 80, 126);
                    g.fillRoundRect(xState - (font1.stringWidth(pet[iPet].title) + 10) / 2, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5, font1.stringWidth(pet[iPet].title) + 10, 3 * font1.getHeight() / 2, 5, 5);
                    g.setColor(0xffffff);
                    g.drawString(pet[iPet].title, xState, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + font1.getHeight() / 4, Graphics.TOP | Graphics.HCENTER);
                } else if (pet[iPet].getState() >= Pet.STATE_CHICK_SMALL) {
                    pet[iPet].chickMove();
                    g.setColor(1, 80, 126);
                    g.fillRoundRect(xState - (font1.stringWidth(pet[iPet].title) + 10) / 2, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5, font1.stringWidth(pet[iPet].title) + 10, 3 * font1.getHeight() / 2, 5, 5);
                    g.setColor(0xffffff);
                    g.drawString(pet[iPet].title, xState, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + font1.getHeight() / 4, Graphics.TOP | Graphics.HCENTER);
                }
            }
            g.setFont(font1);
            g.setColor(1, 80, 126);
            int stWidth = font1.stringWidth("- Thời gian : 00 : 00 : 00") + 10;
            g.fillRoundRect(xState - stWidth / 2, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2, stWidth, 3 * font1.getHeight() / 2, 5, 5);
            g.fillRoundRect(xState - stWidth / 2, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + 3 * font1.getHeight() / 2 + 5, stWidth, 3 * font1.getHeight() / 2, 5, 5);
            g.fillRoundRect(xState - stWidth / 2, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + 2 * (3 * font1.getHeight() / 2 + 5), stWidth, 3 * font1.getHeight() / 2, 5, 5);
            g.fillRoundRect(xState - stWidth / 2, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + 3 * (3 * font1.getHeight() / 2 + 5), stWidth, 3 * font1.getHeight() / 2, 5, 5);
            g.setColor(0xffffff);
            g.drawString("- Level : " + pet[iPet].level, xState - stWidth / 2 + 5, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + font1.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
            g.drawString("- Exp : " + pet[iPet].exp, xState - stWidth / 2 + 5, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + 3 * font1.getHeight() / 2 + 5 + font1.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
            g.drawString("- Next Level : " + nextLevel[iPet], xState - stWidth / 2 + 5, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + 2 * (3 * font1.getHeight() / 2 + 5) + font1.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
            Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+7"));
            Date date = new Date();
            calendar.setTime(date);
            String sTime = calendar.get(Calendar.HOUR_OF_DAY) + ":" + (calendar.get(Calendar.MINUTE) < 10 ? "0" : "") + calendar.get(Calendar.MINUTE) + ":" + (calendar.get(Calendar.SECOND) < 10 ? "0" : "") + calendar.get(Calendar.SECOND);
//            g.drawString("- Thời gian : " + min + " :" + sec, xState - stWidth / 2 + 5, 10 + 3 * font2.getHeight() / 2 + pet1.pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + 2 * (3 * font3.getHeight() / 2 + 5) + font3.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
            g.drawString("- Thời gian : " + sTime, xState - stWidth / 2 + 5, 10 + 3 * font2.getHeight() / 2 + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight() / 2 + 3 * (3 * font3.getHeight() / 2 + 5) + font3.getHeight() / 4, Graphics.TOP | Graphics.LEFT);
            fillRectPointerPressed(g);
            g.setFont(font3);
            g.setColor(0xffffff);
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        } else if (iInfo == 2) {
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            bottleHP.setVisible(true);
            bottleMP.setVisible(true);
            iconFood.setVisible(true);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            if (xState < this.getWidth() / 2) {
                xState += this.getWidth() / 6;
            } else {
                xState = this.getWidth() / 2;
            }
            if (pet[iPet].level >= 2) {
                pet[iPet].chickMove();
            }
            pet[iPet].pet.setVisible(true);
            pet[iPet].pet.setPosition(xState - pet[iPet].pet.getWidth() / 2, 10 + 3 * font2.getHeight() / 2);
            int strw = font1.stringWidth("  Đấu trường 1");
            if (pet[iPet].level >= 2) {
                key.setVisible(true);
                key.setPosition(xState - (key.getWidth() + strw) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 15);
            }
            int strw1 = font1.stringWidth("  x00");
            iconFood.setPosition(xState - (iconFood.getWidth() + strw1) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 15 + key.getHeight());
            bottleHP.setPosition(xState - (iconFood.getWidth() + strw1) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 15 + key.getHeight() + iconFood.getHeight());
            bottleMP.setPosition(xState - (iconFood.getWidth() + strw1) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 15 + key.getHeight() + iconFood.getHeight() + bottleHP.getHeight());
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(1, 80, 126);
            g.fillRoundRect(xState - (font2.stringWidth("Trang bị") + 10) / 2, 5, font2.stringWidth("Trang bị") + 10, 3 * font2.getHeight() / 2, 5, 5);
            g.setColor(0xffffff);
            g.setFont(font1);
            if (key.isVisible()) {
                g.drawString("  Đấu trường " + (numberArena), xState - (key.getWidth() + strw) / 2 + key.getWidth(), key.getY() + key.getHeight() / 2 - font1.getHeight() / 2, Graphics.TOP | Graphics.LEFT);
            }
            g.drawString(" x" + noFood, iconFood.getX() + iconFood.getWidth(), iconFood.getY(), Graphics.TOP | Graphics.LEFT);
            g.drawString(" x" + noBottleHP, bottleHP.getX() + bottleHP.getWidth(), bottleHP.getY(), Graphics.TOP | Graphics.LEFT);
            g.drawString(" x" + noBottleMP, bottleMP.getX() + bottleMP.getWidth(), bottleMP.getY(), Graphics.TOP | Graphics.LEFT);
            g.setFont(font2);
            g.drawString("Trang bị", xState, 5 + font2.getHeight() / 4, Graphics.TOP | Graphics.HCENTER);
            g.setFont(font3);
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        } else if (iInfo == 3) {
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            key.setVisible(false);
            pet[iPet].pet.setVisible(true);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            drawInfoFight(g);
        } else if (iInfo == 4) {
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            key.setVisible(false);
            pet[iPet].pet.setVisible(false);
            listChooseSkill.setVisible(true);
            listAddChooseSkill.setVisible(true);
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            drawSkillFight(g);
        }
        flushGraphics();
    }

    public void drawInfoScreen128(Graphics g) {
        if (iInfo == 0) {
            key.setVisible(false);
            pet[iPet].pet.setVisible(false);
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            if (xInfo < this.getWidth() / 2) {
                xInfo += this.getWidth() / 6;
            } else {
                xInfo = this.getWidth() / 2;
            }
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(0xffffff);
            g.setFont(font3);
            g.drawString("Tình trạng thú nuôi", xInfo, 0, Graphics.TOP | Graphics.HCENTER);
            g.setFont(font1);
            g.drawString("Vệ sinh: " + pet[iPet].cleanPoint + "%", xInfo, font3.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Thức ăn: " + pet[iPet].foodPoint + "%", xInfo, font3.getHeight() + 5 + 1 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Học tập: " + pet[iPet].learnPoint + "%", xInfo, font3.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Giải trí: " + pet[iPet].relaxPoint + "%", xInfo, font3.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Sức khỏe: " + pet[iPet].helthPoint + "%", xInfo, font3.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        } else if (iInfo == 1) {
            key.setVisible(false);
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            if (xState < this.getWidth() / 2) {
                xState += this.getWidth() / 6;
            } else {
                xState = this.getWidth() / 2;
            }
            pet[iPet].pet.setVisible(true);
            pet[iPet].pet.setPosition(xState - pet[iPet].pet.getWidth() / 2, 5 + font3.getHeight());
            g.setFont(font3);
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(0xffffff);
            g.drawString("Giai đoạn phát triển", xState, 0, Graphics.HCENTER | Graphics.TOP);
            g.setFont(font1);
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            g.drawString("- Level : " + pet[iPet].level, xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5, Graphics.TOP | Graphics.HCENTER);
            g.drawString("- Exp : " + pet[iPet].exp, xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5 + font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
            g.drawString("- Next Level : " + nextLevel[iPet], xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5 + 2 * font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        } else if (iInfo == 2) {
            bottleHP.setVisible(true);
            bottleMP.setVisible(true);
            iconFood.setVisible(true);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            if (xState < this.getWidth() / 2) {
                xState += this.getWidth() / 6;
            } else {
                xState = this.getWidth() / 2;
            }
            if (pet[iPet].level >= 2) {
                pet[iPet].chickMove();
            }
            pet[iPet].pet.setVisible(true);
            pet[iPet].pet.setPosition(xState - pet[iPet].pet.getWidth() / 2, 5 + font3.getHeight());
            int strw = font1.stringWidth("  Đấu trường 1");
            if (pet[iPet].level >= 2) {
                key.setVisible(true);
                key.setPosition(xState - (key.getWidth() + strw) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5);
            }
            int strw1 = font1.stringWidth("  x10");
            iconFood.setPosition(xState - (iconFood.getWidth() + strw1) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 15 + key.getHeight());
            bottleHP.setPosition(xState - (iconFood.getWidth() + strw1) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 15 + key.getHeight() + iconFood.getHeight());
            bottleMP.setPosition(xState - (iconFood.getWidth() + strw1) / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 15 + key.getHeight() + iconFood.getHeight() + bottleHP.getHeight());
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
//            g.setColor(1, 80, 126);
//            g.fillRoundRect(xState - (font2.stringWidth("Trang bị") + 10) / 2, 5, font2.stringWidth("Trang bị") + 10, 3 * font2.getHeight() / 2, 5, 5);
            g.setColor(0xffffff);
            g.setFont(font1);
            if (key.isVisible()) {
                g.drawString("  Đấu trường " + (numberArena), xState - (key.getWidth() + strw) / 2 + key.getWidth(), key.getY() + key.getHeight() / 2 - font1.getHeight() / 2, Graphics.TOP | Graphics.LEFT);
            }
            g.drawString(" x" + noFood, iconFood.getX() + iconFood.getWidth(), iconFood.getY(), Graphics.TOP | Graphics.LEFT);
            g.drawString(" x" + noBottleHP, bottleHP.getX() + bottleHP.getWidth(), bottleHP.getY(), Graphics.TOP | Graphics.LEFT);
            g.drawString(" x" + noBottleMP, bottleMP.getX() + bottleMP.getWidth(), bottleMP.getY(), Graphics.TOP | Graphics.LEFT);
            g.setFont(font3);
            g.drawString("Trang bị", xState, 5 + font2.getHeight() / 4, Graphics.TOP | Graphics.HCENTER);
            g.setFont(font1);
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        } else if (iInfo == 3) {
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            key.setVisible(false);
            pet[iPet].pet.setVisible(true);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            drawInfoFight(g);
        } else if (iInfo == 4) {
            for (int i = 0; i < subMenu1.length; i++) {
                subMenu1[i].setVisible(false);
                infoLine[i].setVisible(false);
            }
            bottleHP.setVisible(false);
            bottleMP.setVisible(false);
            iconFood.setVisible(false);
            key.setVisible(false);
            pet[iPet].pet.setVisible(false);
            listChooseSkill.setVisible(true);
            listAddChooseSkill.setVisible(true);
            g.setColor(2, 140, 253);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            drawSkillFight(g);
        }
        flushGraphics();
    }

    public void fillRectPointerPressed(Graphics g) {
        if (isPointerMenuLeftPressed) {
            g.setColor(0xffff00);
            g.fillRoundRect(0, this.getHeight() - 3 * font3.getHeight() / 2, font3.stringWidth("Đồng ý") + 5, 3 * font3.getHeight() / 2, 5, 5);
        }
        if (isPointMenuRightPressed) {
            g.setColor(0xffff00);
            g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 3 * font3.getHeight() / 2, font3.stringWidth("Trở về") + 5, 3 * font3.getHeight() / 2);
        }
        if (isPointOKPresse) {
            g.setColor(0xffff00);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth("Bắt đầu") / 2, this.getHeight() - 3 * font1.getHeight() / 2, font1.stringWidth("Bắt đầu"), 3 * font1.getHeight() / 2, 5, 5);
            g.setColor(0xffffff);
        }
    }

    public void drawAnnouncement(Graphics g) {
        boolean isDraw = false;
        String str1 = "", str2 = "";
        if (timeDrawAnouce >= 2000) {
            isDrawAnouce = false;
            timeDrawAnouce = 0;
        }
        if (pet[iPet].getState() == Pet.STATE_EGG) {
            if (pet[iPet].exp <= 2) {
                str1 = "Còn 3 phút nữa ";
                str2 = "trứng sẽ nở !";
                isDraw = true;
            }
        }
        if (pet[iPet].getState() == Pet.STATE_EGG_NUT) {
            if (pet[iPet].exp <= 33) {
                str1 = "Hura trứng đã nứt ^^ ";
                str2 = "Lên level 1 rồi !";
                isDraw = true;
            }
        }
        if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
            if (pet[iPet].exp >= 60 && pet[iPet].exp <= 61) {
                str1 = "Trứng đã nở rồi ! ";
                str2 = "Chăm sóc thôi !";
                isDraw = true;
            }
            if (pet[iPet].exp >= 62 && pet[iPet].exp <= 63) {
                str1 = "Gà con cute quá !";
                str2 = "Dọn dẹp nào !";
                isDraw = true;
            }
        }
        if (isDraw) {
            g.setFont(font1);
            g.setColor(230, 225, 153);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 5 * font1.getHeight() / 2, 5, 5);
            g.setColor(112, 142, 142);
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 5 * font1.getHeight() / 2 + 3, 5, 5);
            g.setColor(0x000000);
            g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
            g.drawString(str2, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
        }
    }

    public void drawSavePetSuccess(Graphics g) {
        boolean isDraw = true;
        String str1 = "Gửi thú nuôi thành công",
                str2 = "Bạn có thể yên tâm rồi !";
        if (isDraw) {
            g.setFont(font1);
            g.setColor(230, 225, 153);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 5 * font1.getHeight() / 2, 5, 5);
            g.setColor(112, 142, 142);
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 5 * font1.getHeight() / 2 + 3, 5, 5);
            g.setColor(0x000000);
            g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
            g.drawString(str2, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
        }
    }

    public void drawPetThink1(Graphics g) {
        String str1 = "";
        if (!isNotEnoughMoneyBuyFood) {
            if (pet[iPet].cleanPoint <= 0) {
                str1 = "Hic! Bẩn quá!";
            } else if (pet[iPet].foodPoint <= 0) {
                str1 = "Hu hu ! Đói";
            } else if (pet[iPet].learnPoint <= 0) {
                str1 = "Thèm học quá !";
            } else if (pet[iPet].helthPoint <= 0) {
                str1 = "Ốm rùi T_T";
            } else if (pet[iPet].relaxPoint <= 0) {
                str1 = "Muốn chơi Audition";
            }
        } else {
            str1 = "Hết tiền !";
        }
        g.setFont(font1);
//            g.setColor(1, 70, 110);
        g.setColor(230, 225, 153);
        g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 3 * font1.getHeight() / 2, 5, 5);
        g.setColor(112, 142, 142);
        g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
//            g.setColor(0xffffff);
        g.setColor(0x000000);
        g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
//        g.drawString(str2, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet1.pet.getY() - 5 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
    }

    public void drawNoCare(Graphics g) {
        String str1 = "";
        if (isDrawNoCareClean) {
            str1 = "Vẫn còn sạch mà";
        } else if (isDrawNoCareDoctor) {
            str1 = "Sợ tiêm lắm";
        } else if (isDrawNoCareEat) {
            str1 = "Chưa đói mà";
        } else if (isDrawNoCareLearn) {
            str1 = "Èo ! Vừa học xong!";
        } else if (isDrawEmptyFood) {
            str1 = "Hết thức ăn!";
        }
        g.setFont(font1);
        g.setColor(230, 225, 153);
        g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, /*pet[iPet]*/ face.getY() - 3 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 3 * font1.getHeight() / 2, 5, 5);
        g.setColor(112, 142, 142);
        g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, /*pet[iPet].pet*/ face.getY() - 3 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
        g.setColor(0x000000);
        g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, /*pet[iPet].pet*/ face.getY() - 5 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
        face.nextFrame();
    }

    public void drawPetThink(Graphics g) {
        String str1 = "", str2 = "";
        if (isCleaning) {
            str1 = "Quét dọn sạch sẽ nào !";
        }
        if (isLearning) {
            str1 = "Học bài chăm chỉ nào !";
        }
        if (isEating) {
            str1 = "Măm măm ! Ực ực !";
        }
        if (isDoctor) {
            str1 = "Tiêm thuốc nào !";
        }
        if (!isEating) {
            g.setFont(font1);
            g.setColor(230, 225, 153);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 3 * font1.getHeight() / 2, 5, 5);
            g.setColor(112, 142, 142);
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
            g.setColor(0x000000);
            g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
        } else {
            g.setFont(font1);
            g.setColor(230, 225, 153);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, face.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 3 * font1.getHeight() / 2, 5, 5);
            g.setColor(112, 142, 142);
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, face.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
            g.setColor(0x000000);
            g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, face.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
        }
    }

    public void drawPetFinishChamsoc(Graphics g) {
        String str1 = "", str2 = "";
        if (isCleaning) {
            str1 = "Mát quá !Thích quá ^^ !";
        }
        if (isLearning) {
            str1 = "Hi hi, Được điểm 10 !";
        }
        if (isDoctor) {
            str1 = "Khỏe quá !Ha ha >'<!";
        }
        if (isEating) {
            str1 = "No quá !";
        }
        g.setFont(font1);
        g.setColor(112, 142, 142);
        g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, pet[iPet].pet.getY() - 20 - 3 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
        g.setColor(230, 225, 153);
        g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 20 - 3 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 3 * font1.getHeight() / 2, 5, 5);
        g.fillTriangle(this.getWidth() / 2 - font1.stringWidth(str1) / 2 + 20, pet[iPet].pet.getY() - 20, pet[iPet].getX() + pet[iPet].pet.getWidth() / 2, pet[iPet].pet.getY(), this.getWidth() / 2 - font1.stringWidth(str1) / 2 + 30, pet[iPet].pet.getY() - 20);
        g.setColor(112, 142, 142);
        g.drawLine(this.getWidth() / 2 - font1.stringWidth(str1) / 2 + 20, pet[iPet].pet.getY() - 20, pet[iPet].getX() + pet[iPet].pet.getWidth() / 2, pet[iPet].pet.getY());
        g.drawLine(this.getWidth() / 2 - font1.stringWidth(str1) / 2 + 30, pet[iPet].pet.getY() - 20, pet[iPet].getX() + pet[iPet].pet.getWidth() / 2, pet[iPet].pet.getY());
        g.setColor(0x000000);
        g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 20 - 5 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
    }

    public void drawSkillFight(Graphics g) {
        if (xState < this.getWidth() / 2) {
            xState += this.getWidth() / 6;
        } else {
            xState = this.getWidth() / 2;
        }
        listChooseSkill.setVisible(true);
        listChooseSkill.setPosition(xState - (this.getWidth() / 2 - 5), this.getHeight() / 2 - listChooseSkill.getHeight() / 2);
        listAddChooseSkill.setVisible(true);
        listAddChooseSkill.setPosition(listChooseSkill.getX(), listChooseSkill.getY());
        for (int i = 0; i < listAddChooseSkill.getRows(); i++) {
            if (isUseSkill[i]) {
                listAddChooseSkill.setCell(0, i, 0);
            } else {
                listAddChooseSkill.setCell(0, i, 1);
            }
        }
        if (isThiDau) {
            g.setColor(87, 87, 87);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            lmFight.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmFight.paint(g, 0, 0);
        } else {
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        }
        g.setColor(0xff0000);
        g.drawRoundRect(listChooseSkill.getX(), listChooseSkill.getY() + iChooseSkillFight * listChooseSkill.getCellHeight(), listChooseSkill.getCellWidth(), listChooseSkill.getCellHeight(), 5, 5);
        g.setColor(0xffffff);
        if (this.getWidth() >= 200) {
            g.setFont(font2);
            if (iChooseSkillFight < 6) {
                g.drawString(skillName[iChooseSkillFight] + " Lv " + skilllv[iChooseSkillFight], listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, listChooseSkill.getY(), Graphics.TOP | Graphics.HCENTER);
            } else {
                g.drawString(skillName[iChooseSkillFight], listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, listChooseSkill.getY(), Graphics.TOP | Graphics.HCENTER);
            }
        } else {
            g.setFont(font3);
            if (iChooseSkillFight < 6) {
                g.drawString(skillName[iChooseSkillFight] + " Lv " + skilllv[iChooseSkillFight], listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, 2 * font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
            } else {
                g.drawString(skillName[iChooseSkillFight], listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, 2 * font1.getHeight(), Graphics.TOP | Graphics.HCENTER);
            }
        }
        g.setFont(font1);
        if (this.getWidth() >= 200) {
            if (isUseSkill[iChooseSkillFight]) {
                g.drawString("Công phá : " + dam[iChooseSkillFight] + " đv", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, listChooseSkill.getY() + font2.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("MP : " + mana[iChooseSkillFight], listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, listChooseSkill.getY() + font2.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Chính xác : " + acc[iChooseSkillFight] + "%", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, listChooseSkill.getY() + font2.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Tiền :" + money + "$", 0, 0, Graphics.LEFT | Graphics.TOP);
                g.drawString("SP : " + pet[iPet].skillPoint, this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                if (iChooseSkillFight < 6) {
                    g.drawString("Nâng cấp: " + costSkill[iChooseSkillFight] + "$, " + spSkill[iChooseSkillFight] + "sp", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, listChooseSkill.getY() + font2.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                }
            } else {
                g.drawString("Cấp " + levelUseSkill[iChooseSkillFight] + " mới có thể dùng", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, listChooseSkill.getY() + font2.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            }
        } else {
            if (isUseSkill[iChooseSkillFight]) {
                g.drawString("Công phá : " + dam[iChooseSkillFight] + " đv", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, 2 * font1.getHeight() + font3.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("MP : " + mana[iChooseSkillFight], listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, 2 * font1.getHeight() + font3.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Chính xác : " + acc[iChooseSkillFight] + "%", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, 2 * font1.getHeight() + font3.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Tiền :" + money + "$", this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                g.drawString("SP : " + pet[iPet].skillPoint, this.getWidth(), font1.getHeight(), Graphics.RIGHT | Graphics.TOP);
                if (iChooseSkillFight < 6) {
                    g.drawString("Nâng cấp: " + costSkill[iChooseSkillFight] + "$, " + spSkill[iChooseSkillFight] + "sp", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, 2 * font1.getHeight() + font3.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                }
            } else {
                g.drawString("Cấp " + levelUseSkill[iChooseSkillFight] + " mới có thể dùng", listChooseSkill.getX() + listChooseSkill.getWidth() + (this.getWidth() - listChooseSkill.getX() - listChooseSkill.getWidth()) / 2, 2 * font1.getHeight() + font3.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            }
        }
        fillRectPointerPressed(g);
        g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
        if (skilllv[iChooseSkillFight] < 3 && iChooseSkillFight < 6) {
            g.drawString("UP", this.getWidth() / 2, this.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
        }
        if (isThiDau) {
            flushGraphics();
        }
    }

    public void drawCanFight(Graphics g) {
        String str1 = "Hãy đợi trứng nở !";
        g.setFont(font1);
//            g.setColor(1, 70, 110);
        g.setColor(230, 225, 153);
        g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 3 * font1.getHeight() / 2, 5, 5);
        g.setColor(112, 142, 142);
        g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str1) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
//            g.setColor(0xffffff);
        g.setColor(0x000000);
        g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
    }

    public void drawTrainScreen(Graphics g) {
        if (isTrainBeginUp) {
            if (this.getWidth() >= 200) {
                if (trainArrow.getY() > topMainMenu + 15) {
                    trainArrow.move(0, -10);
                } else {
                    trainArrow.setPosition(this.getWidth() / 2 - trainArrow.getWidth() / 2, topMainMenu + 15);
                    isTrainBeginUp = false;
                }
            } else {
                if (trainArrow.getY() > this.getHeight() - trainArrow.getHeight()) {
                    trainArrow.move(0, -10);
                } else {
                    trainArrow.setPosition(this.getWidth() / 2 - trainArrow.getWidth() / 2, this.getHeight() - trainArrow.getHeight());
                    isTrainBeginUp = false;
                }
            }
            if (xTrainScreen < 2 * font1.getHeight() + 15) {
                xTrainScreen += 5;
            } else {
                xTrainScreen = 2 * font1.getHeight() + 15;
            }
        }
        if (isTrainBeginDown) {
            if (trainArrow.getY() <= this.getHeight() + 5) {
                trainArrow.move(0, 10);
            } else {
                trainArrow.setPosition(this.getWidth() / 2 - trainArrow.getWidth() / 2, this.getHeight() + 5);
                isTrainBeginDown = false;
                isTrain = false;
            }
            if (xTrainScreen >= 0) {
                xTrainScreen -= 5;
            } else {
                xTrainScreen = 0;
            }
        }
        lm.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lm.paint(g, 0, 0);
        g.setFont(font1);
        g.setColor(1, 80, 126);
        g.fillRect(0, 0, this.getWidth(), xTrainScreen);
        g.fillRoundRect(0, 0, this.getWidth(), xTrainScreen + 7, 7, 7);
        if (this.getWidth() >= 200) {
            g.drawString("OK", this.getWidth() / 2, this.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
        } else {
            g.drawString("x", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
        }
        g.setColor(0xffffff);
        if (!isTrainBeginUp) {
            if (pet[iPet].relaxPoint <= 0) {
                g.drawString("Điểm:" + scoreTrain + "/" + needScoreTrain, 0, 5, Graphics.TOP | Graphics.LEFT);
            } else {
                g.drawString("Điểm:" + scoreTrain, 0, 5, Graphics.TOP | Graphics.LEFT);
            }
            g.drawString("Kĩ năng:" + pet[iPet].skillPoint, 0, 5 + font1.getHeight(), Graphics.TOP | Graphics.LEFT);
            String sTime = "";
            if (timeTrain > 0) {
                sTime = (timeTrain / 60000 < 10 ? "0" : "") + timeTrain / 60000 + ":" + ((timeTrain / 1000) % 60 < 10 ? "0" : "") + (timeTrain / 1000) % 60;
            } else {
                sTime = "00:00";
            }
            g.drawString(sTime, this.getWidth(), 5, Graphics.RIGHT | Graphics.TOP);
        }
        if (isPointMenuRightPressed) {
            g.setColor(0xffff00);
            g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 3 * font3.getHeight() / 2, font3.stringWidth("Trở về") + 5, 3 * font3.getHeight() / 2);
        }
        g.setColor(145, 217, 249);
        g.fillRoundRect(trainArrow.getX(), trainArrow.getY() - 20, trainArrow.getWidth(), 12, 12, 12);
        g.setColor(234, 227, 159);
        g.fillRoundRect(trainArrow.getX() + 3 * trainArrow.getWidth() / 4, trainArrow.getY() - 20, 8, 12, 5, 5);
//        g.setColor(0xff0000);
//        g.drawRoundRect(trainArrow.getX(), trainArrow.getY() - 21, trainArrow.getWidth(), 13, 12, 12);
        if (!isTrainBeginUp) {
            if (xLight + lightTrain.getWidth() < trainArrow.getX() + trainArrow.getWidth()) {
//                if (scoreTrain < 200) {
//                    xLight++;
//                } else {
//                    xLight += 2;
//                }
                xLight += 1;
            } else {
                xLight = trainArrow.getX();
                if (isArrowPressed) {
                    randomTrainArrow();
                }
            }
        }
        if (!isTrainBeginDown) {
            g.drawImage(light, xLight, trainArrow.getY() - 20, Graphics.LEFT | Graphics.TOP);
        }
        if (isStartTrain) {
            String str2 = "", str4 = "Bạn có " + timeTrain / 60000 + " phút", str3 = "START";
            if (pet[iPet].relaxPoint <= 0) {
                if (this.getWidth() >= 200) {
                    str2 = "Bạn cần đạt " + needScoreTrain + " điểm";
                } else {
                    str2 = needScoreTrain + " điểm";
                }
            } else {
                if (this.getWidth() >= 200) {
                    str2 = "50 điểm sẽ tăng 1 điểm kĩ năng";
                } else {
                    str2 = "50 điểm / 1 sp";
                }
            }
            g.setColor(230, 225, 153);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str2) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str2) + 10, 3 * font1.getHeight() / 2, 5, 5);
            g.setColor(112, 142, 142);
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str2) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str2) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
            g.setColor(0x000000);
            if (timeStartTrain <= 1500) {
                g.drawString(str2, this.getWidth() / 2 - font1.stringWidth(str2) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
            } else if (timeStartTrain <= 2500) {
                g.drawString(str4, this.getWidth() / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.HCENTER | Graphics.TOP);
            } else if (timeStartTrain <= 3000) {
                g.drawString(str3, this.getWidth() / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.HCENTER | Graphics.TOP);
            } else {
                timeStartTrain = 0;
                isStartTrain = false;
            }
        }
        if (timeTrain <= 0) {
            if (timeCoutTrain >= 1500) {
                isTrainBeginDown = false;
                isTrain = false;
                for (int i = 0; i < subMenu1.length; i++) {
                    subMenu1[i].setPosition((i - subMenu1.length) * subMenu1[i].getWidth(), topMainMenu);
                    subMenu1[i].setVisible(true);
                }
                pointer.setVisible(true);
                pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
                pet[iPet].pet.setVisible(true);
                pet[iPet].isDance = false;
                if (pet[iPet].level >= 2) {
                    if (pet[iPet].checkTired()) {
                        pet[iPet].pet.setFrame(6);
                    } else {
                        pet[iPet].pet.setFrame(18);
                    }
                }
                if (pet[iPet].relaxPoint > 0) {
                    thinking.setVisible(false);
                    iconThinking.setVisible(false);
                }
                trainArrow.setPosition(this.getWidth() / 2 - trainArrow.getWidth() / 2, this.getHeight() + 5);
            }
            String str2 = "Hết giờ";
            g.setColor(230, 225, 153);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str2) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str2) + 10, 3 * font1.getHeight() / 2, 5, 5);
            g.setColor(112, 142, 142);
            g.drawRoundRect(this.getWidth() / 2 - font1.stringWidth(str2) / 2 - 5 - 2, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2 - 2, font1.stringWidth(str2) + 10 + 3, 3 * font1.getHeight() / 2 + 3, 5, 5);
            g.setColor(0xff0000);
            g.drawString(str2, this.getWidth() / 2 - font1.stringWidth(str2) / 2, pet[iPet].pet.getY() - 9 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
        }
        if (isDrawTrainMiss) {
            if (timeTrainMiss <= 1000) {
                String str1 = "Ọc! Miss rồi !";
                g.setFont(font1);
                g.setColor(1, 80, 126);
                g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 5 * font1.getHeight() / 2, 5, 5);
                g.setColor(0xffffff);
                g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 7 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
            }
            if (timeTrainMiss >= 1000) {
                isDrawTrainMiss = false;
                timeTrainMiss = 0;
            }
        }
        if (isDrawTrainFinish) {
            if (timeTrainFinish <= 1000) {
                String str1 = "Yeah ! Giỏi quá !";
                g.setFont(font1);
                g.setColor(1, 80, 126);
                g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth(str1) / 2 - 5, pet[iPet].pet.getY() - 5 * font1.getHeight() / 2, font1.stringWidth(str1) + 10, 5 * font1.getHeight() / 2, 5, 5);
                g.setColor(0xffffff);
                g.drawString(str1, this.getWidth() / 2 - font1.stringWidth(str1) / 2, pet[iPet].pet.getY() - 7 * font1.getHeight() / 4, Graphics.LEFT | Graphics.TOP);
            }
            if (timeTrainFinish >= 1000) {
                isDrawTrainFinish = false;
                timeTrainFinish = 0;
            }
        }
        if (isAddSkillTrain) {
            if (timeAddSkillTrain <= 1000) {
                g.setColor(0xff0000);
                g.setFont(font2);
                String str1 = "+1SP";
                if (timeAddSkillTrain > pet[iPet].getY() - 5 * font1.getHeight() / 2 - 30) {
                    timeAddSkillTrain -= 4;
                } else {
                    isAddSkillTrain = false;
                }
                g.drawString(str1, this.getWidth() / 2, timeAddSkillTrain, Graphics.HCENTER | Graphics.BOTTOM);
            }
        }
        flushGraphics();
    }

    public void drawFightScreenMenu(Graphics g) {
        g.setColor(0x000000);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        if (this.getWidth() >= 200) {
            g.setFont(font2);
            int strW = font2.stringWidth("Chọn đấu trường");
            g.setColor(0, 128, 192);
            g.fillRoundRect(this.getWidth() / 2 - strW / 2 - 10, this.getHeight() / 2 - (4 * font2.getHeight() + 30) / 2 + iMenuFight * (10 + font2.getHeight()), strW + 20, font2.getHeight(), font2.getHeight(), font2.getHeight());
            g.setColor(0xffffff);
            g.drawString("Chọn đấu trường", this.getWidth() / 2, this.getHeight() / 2 - (4 * font2.getHeight() + 30) / 2, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Đối thủ", this.getWidth() / 2, this.getHeight() / 2 - (4 * font2.getHeight() + 30) / 2 + 10 + yMenuFight, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Thi đấu", this.getWidth() / 2, this.getHeight() / 2 - (4 * font2.getHeight() + 30) / 2 + 20 + /*font2.getHeight()*/ 2 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Thoát", this.getWidth() / 2, this.getHeight() / 2 - (4 * font2.getHeight() + 30) / 2 + 30 + /*font2.getHeight()*/ 3 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
//            g.drawString("Thi đấu", this.getWidth() / 2, this.getHeight() / 2 - (6 * font2.getHeight() + 30) / 2 + 40 + /*2 * font2.getHeight()*/ 4 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
//            g.drawString("Thoát", this.getWidth() / 2, this.getHeight() / 2 - (6 * font2.getHeight() + 30) / 2 + 50 + /*3 * font2.getHeight()*/ 5 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
        } else {
            g.setFont(font1);
            int strW = font1.stringWidth("Chọn đấu trường");
            g.setColor(0, 128, 192);
            g.fillRoundRect(this.getWidth() / 2 - strW / 2 - 10, this.getHeight() / 2 - (4 * font1.getHeight() + 30) / 2 + iMenuFight * (0 + font1.getHeight()), strW + 20, font1.getHeight(), font1.getHeight(), font1.getHeight());
            g.setColor(0xffffff);
            g.drawString("Chọn đấu trường", this.getWidth() / 2, this.getHeight() / 2 - (4 * font1.getHeight() + 30) / 2, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Đối thủ", this.getWidth() / 2, this.getHeight() / 2 - (4 * font1.getHeight() + 30) / 2 + 0 + yMenuFight, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Thi đấu", this.getWidth() / 2, this.getHeight() / 2 - (4 * font1.getHeight() + 30) / 2 + 0 + /*font2.getHeight()*/ 2 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Thoát", this.getWidth() / 2, this.getHeight() / 2 - (4 * font1.getHeight() + 30) / 2 + 0 + /*font2.getHeight()*/ 3 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
//            g.drawString("Thi đấu", this.getWidth() / 2, this.getHeight() / 2 - (6 * font1.getHeight() + 30) / 2 + 0 + /*2 * font2.getHeight()*/ 4 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
//            g.drawString("Thoát", this.getWidth() / 2, this.getHeight() / 2 - (6 * font1.getHeight() + 30) / 2 + 0 + /*3 * font2.getHeight()*/ 5 * yMenuFight, Graphics.HCENTER | Graphics.TOP);
        }
        if (this.getWidth() >= 200) {
            if (yMenuFight < font2.getHeight()) {
                yMenuFight += font2.getHeight() / 2;
            } else {
                yMenuFight = font2.getHeight();
            }
        } else {
            if (yMenuFight < font1.getHeight()) {
                yMenuFight += font1.getHeight() / 2;
            } else {
                yMenuFight = font1.getHeight();
            }
        }
        g.setColor(0xff0000);
        if (isAlert) {
            g.setFont(font1);
            if (this.getWidth() >= 200) {
                g.drawString("Chọn đối thủ trước!", this.getWidth() / 2, this.getHeight() / 2 - (6 * font2.getHeight() + 30) / 2 + 50 + 6 * font2.getHeight() + 10, Graphics.HCENTER | Graphics.TOP);
            } else {
                g.drawString("Chọn đối thủ trước!", this.getWidth() / 2, this.getHeight() / 2 - (6 * font1.getHeight() + 30) / 2 + 0 + 6 * font1.getHeight() + 10, Graphics.HCENTER | Graphics.TOP);
            }
        }
        face.setVisible(false);
        flushGraphics();
    }

    public void drawInfoFight(Graphics g) {
        if (isThiDau) {
            g.setColor(87, 87, 87);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
        }
        if (xState < this.getWidth() / 2) {
            xState += this.getWidth() / 6;
        } else {
            xState = this.getWidth() / 2;
        }
        if (this.getWidth() > 160) {
            g.setFont(font2);
            g.setColor(0xffffff);
            g.drawString("Kĩ năng", /*this.getWidth() / 2*/ xState, 5, Graphics.HCENTER | Graphics.TOP);
        }
        if (this.getWidth() >= 160) {
            if (pet[iPet].level > 2) {
                pet[iPet].chickMove();
            }
            pet[iPet].pet.setVisible(true);
            pet[iPet].pet.setPosition(/*this.getWidth() / 2*/xState - pet[iPet].pet.getWidth() / 2, 10 + 3 * font2.getHeight() / 2);
        } else {
            pet[iPet].pet.setPosition(/*this.getWidth() / 2*/xState - pet[iPet].pet.getWidth() / 2, font1.getHeight());
        }
        choosenFight.setVisible(false);
        if (isThiDau) {
            lmFight.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmFight.paint(g, 0, 0);
        } else {
            lmInfo.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmInfo.paint(g, 0, 0);
        }
        if (isPointMenuRightPressed) {
            g.setColor(0xffff00);
            g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 2 * font3.getHeight(), font3.stringWidth("Trở về") + 5, 2 * font3.getHeight());
        }
        int strW = font1.stringWidth("Kĩ năng : " + pet[iPet].skillPoint) + 10;
        g.setColor(0x0000ff);
        g.fillRoundRect(this.getWidth() / 2 - strW / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + font1.getHeight() + 5 + iUpInfo * font1.getHeight(), strW, font1.getHeight(), 5, 5);
        g.setColor(0xffffff);
        g.setFont(font1);
        g.drawString(money + "$", 0, 0, Graphics.LEFT | Graphics.TOP);
        g.drawString(pet[iPet].skillPoint + "sp", this.getWidth(), 0, Graphics.TOP | Graphics.RIGHT);
        g.drawString("Level : " + pet[iPet].level, /*this.getWidth() / 2*/ xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
        g.drawString("MP : " + pet[iPet].mp, /*this.getWidth() / 2*/ xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("HP : " + pet[iPet].hp, /*this.getWidth() / 2*/ xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Công : " + pet[iPet].attack, /*this.getWidth() / 2*/ xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Thủ : " + pet[iPet].defend, /*this.getWidth() / 2*/ xState, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        if (7 * font1.getHeight() < this.getHeight()) {
            g.setColor(0xff0000);
            g.drawString("Nâng cấp: " + costUpInfo[iUpInfo] + "$, " + spUpInfo[iUpInfo] + "sp", this.getWidth() / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + 5 + 5 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        }
        fillRectPointerPressed(g);
        g.setColor(0xffffff);
        if (this.getWidth() >= 200) {
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
        } else {
            g.drawString("x", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
        }
        g.drawString("UP", this.getWidth() / 2, this.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
        if (isThiDau) {
            flushGraphics();
        }
    }

    public void drawInfoDoiThu(Graphics g) {
        g.setColor(0x000000);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
//        if (petDoiThu.level > 2) {
//            petDoiThu.chickMove();
//        }
        addSkill.setVisible(false);
        listChooseSkill.setVisible(false);
        listAddChooseSkill.setVisible(false);
        myWind.setVisible(false);
        doithuWind.setVisible(false);
        petDoiThu.pet.setVisible(true);
        if (this.getWidth() > 200) {
            myHPLine.setVisible(false);
            myHpMp.setVisible(false);
            doithuHPline.setVisible(false);
            doithuHpMp.setVisible(false);
        }
        petDoiThu.pet.setPosition(this.getWidth() / 2 - petDoiThu.pet.getWidth() / 2, 10 + 3 * font2.getHeight() / 2);
        lmFight.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lmFight.paint(g, 0, 0);
        if (isPointMenuRightPressed) {
            g.setColor(0xffff00);
            g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 2 * font3.getHeight(), font3.stringWidth("Trở về") + 5, 2 * font3.getHeight());
        }
        int strW = font1.stringWidth("Kĩ năng : " + petDoiThu.skillPoint) + 10;
//        g.setColor(0x0000ff);
//        g.fillRoundRect(this.getWidth() / 2 - strW / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + font1.getHeight() + 5 + iUpInfo * font1.getHeight(), strW, font1.getHeight(), 5, 5);
        g.setColor(0xffffff);
        g.setFont(font1);
        g.drawString(money + "$", 0, 0, Graphics.LEFT | Graphics.TOP);
        g.drawString(petDoiThu.skillPoint + "sp", this.getWidth(), 0, Graphics.TOP | Graphics.RIGHT);
        g.drawString("Level : " + petDoiThu.level, this.getWidth() / 2, petDoiThu.getY() + petDoiThu.pet.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
        g.drawString("MP : " + petDoiThu.mp, this.getWidth() / 2, petDoiThu.getY() + petDoiThu.pet.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("HP : " + petDoiThu.hp, this.getWidth() / 2, petDoiThu.getY() + petDoiThu.pet.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Công : " + petDoiThu.attack, this.getWidth() / 2, petDoiThu.getY() + petDoiThu.pet.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Thủ : " + petDoiThu.defend, this.getWidth() / 2, petDoiThu.getY() + petDoiThu.pet.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        fillRectPointerPressed(g);
        g.setColor(0xffffff);
        if (this.getWidth() >= 200) {
            g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
        } else {
            g.drawString("x", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
        }
        flushGraphics();
    }

    public void drawChooseFight(Graphics g) {
        g.setColor(0x000000);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        if (this.getWidth() >= 200) {
            g.setFont(font2);
        } else {
            g.setFont(font3);
        }
        g.setColor(0xffffff);
        g.drawString("Lựa chọn đối thủ", this.getWidth() / 2, 5, Graphics.HCENTER | Graphics.TOP);
        if (isPointMenuRightPressed) {
            g.setColor(0xffff00);
            g.fillRect(this.getWidth() - font3.stringWidth("Trở về") - 5, this.getHeight() - 2 * font3.getHeight(), font3.stringWidth("Trở về") + 5, 2 * font3.getHeight());
        }
        pet[iPet].pet.setVisible(false);
        choosenFight.setVisible(true);
        listChooseSkill.setVisible(false);
        listAddChooseSkill.setVisible(false);
        if (myArena != null) {
            myArena.setVisible(false);
        }
        listSkill.setVisible(false);
        lmFight.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lmFight.paint(g, 0, 0);
        g.setColor(0xffff00);
        g.drawRoundRect(choosenFight.getX() + iChooseFight * choosenFight.getCellWidth(), choosenFight.getY(), choosenFight.getCellWidth(), choosenFight.getCellHeight(), 5, 5);
        fillRectPointerPressed(g);
        g.setColor(0xffffff);
        g.setFont(font1);
        g.drawString("Level : " + infoDoithu[iChooseFight][0], this.getWidth() / 2, choosenFight.getY() + choosenFight.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
        g.drawString("MP : " + infoDoithu[iChooseFight][1], this.getWidth() / 2, choosenFight.getY() + choosenFight.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("HP : " + infoDoithu[iChooseFight][2], this.getWidth() / 2, choosenFight.getY() + choosenFight.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Kĩ năng : " + infoDoithu[iChooseFight][3], this.getWidth() / 2, choosenFight.getY() + choosenFight.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Công : " + infoDoithu[iChooseFight][4], this.getWidth() / 2, choosenFight.getY() + choosenFight.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Thủ : " + infoDoithu[iChooseFight][5], this.getWidth() / 2, choosenFight.getY() + choosenFight.getHeight() + 5 + 5 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("Tiền cược : " + infoDoithu[iChooseFight][6] + "$", this.getWidth() / 2, choosenFight.getY() + choosenFight.getHeight() + 5 + 6 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        g.drawString("OK", this.getWidth() / 2, this.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
        g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
        flushGraphics();
    }

    public void drawChooseArena(Graphics g) {
        try {
            addSkill.setVisible(false);
            listSkill.setVisible(false);
            listChooseSkill.setVisible(false);
            listAddChooseSkill.setVisible(false);
            if (myWind != null) {
                myWind.setVisible(false);
                doithuWind.setVisible(false);
            }
            if (this.getWidth() > 200) {
                myHPLine.setVisible(false);
                myHpMp.setVisible(false);
                doithuHPline.setVisible(false);
                doithuHpMp.setVisible(false);
            }
            g.setColor(0x000000);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(0xffffff);
            if (this.getWidth() >= 200) {
                g.setFont(font2);
            } else {
                g.setFont(font1);
            }
            g.drawString("Chọn đấu trường", this.getWidth() / 2, 5, Graphics.TOP | Graphics.HCENTER);
            if (this.getWidth() < 200) {
                g.setFont(font1);
            }
            if (this.getWidth() >= 200) {
                g.drawString("<< " + nameArena[iArena] + " >>", this.getWidth() / 2, myArena.getY() + myArena.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            } else {
                if (totalMemory >= 1000000) {
                    g.drawString("<< " + nameArena[iArena] + " >>", this.getWidth() / 2, myArena.getY() + myArena.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
                } else {
                    g.drawString("<< " + nameArena[iArena] + " >>", this.getWidth() / 2, this.getHeight() / 2, Graphics.HCENTER | Graphics.TOP);
                }
            }
            g.setFont(font1);
            if (isPointOKPresse) {
                g.setColor(0xffff00);
                g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth("Bắt đầu") / 2, this.getHeight() - 3 * font1.getHeight() / 2, font1.stringWidth("Bắt đầu"), 3 * font1.getHeight() / 2, 5, 5);
                g.setColor(0xffffff);
            }
            if (iArena > numberArena - 1) {
                keyUnLock.setVisible(true);
                keyUnLock.setFrame(iArena);
                keyUnLock.setPosition(this.getWidth() / 2 - keyUnLock.getWidth() / 2, this.getHeight() - keyUnLock.getHeight());
                if (this.getWidth() >= 200 || totalMemory >= 1000000) {
                    keyUnLock.setPosition(this.getWidth() / 2 - keyUnLock.getWidth() / 2, myArena.getY() + myArena.getHeight() / 2 - keyUnLock.getHeight() / 2);
                }
            } else {
                keyUnLock.setVisible(false);
                fillRectPointerPressed(g);
                g.drawString("OK", this.getWidth() / 2, this.getHeight(), Graphics.BOTTOM | Graphics.HCENTER);
            }
            if (this.getWidth() > 160) {
                if (iArena > numberArena - 1) {
                    addBackArena.setVisible(true);
                    addBackArena.setPosition(0, myArena.getY());
//                g.drawImage(gameDesign.getChe_dau_truong(), myArena.getX(), myArena.getY(), Graphics.TOP | Graphics.LEFT);
                } else {
                    addBackArena.setVisible(false);
                }
            }
            lmFight.setViewWindow(0, 0, this.getWidth(), this.getHeight());
            lmFight.paint(g, 0, 0);
            flushGraphics();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void drawFight(Graphics g) {
        g.setColor(0x000000);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        choosenFight.setVisible(false);
        petDoiThu.pet.setVisible(true);
        if (this.getWidth() >= 200 || totalMemory >= 1000000) {
            myArena.setVisible(true);
            doithuArena.setVisible(true);
        }
        if (this.getWidth() > 160) {
            if (myWind.isVisible()) {
                myWind.nextFrame();
                doithuWind.nextFrame();
            }
        }
        if (isTrailer) {
            if (petDoiThu.getX() > this.getWidth() - petDoiThu.pet.getWidth() - 50) {
                petDoiThu.pet.move(-20, 0);
            } else {
                petDoiThu.pet.setPosition(this.getWidth() - petDoiThu.pet.getWidth() - 50, this.getHeight() / 4 - petDoiThu.pet.getHeight() / 2);
            }
        } else {
            if (this.getWidth() >= 200) {
                petDoiThu.pet.setPosition(this.getWidth() - petDoiThu.pet.getWidth() - 10, this.getHeight() / 4 - petDoiThu.pet.getHeight() / 2);
            } else {
                if (totalMemory > 1000000) {
                    petDoiThu.pet.setPosition(this.getWidth() - petDoiThu.pet.getWidth() - 5, doithuArena.getY() + doithuArena.getHeight() / 2 - petDoiThu.pet.getHeight() / 2);
                } else {
                    petDoiThu.pet.setPosition(this.getWidth() - petDoiThu.pet.getWidth() - 5, 0 + 50 - petDoiThu.pet.getHeight() / 2);
                }
            }
        }
        pet[iPet].pet.setVisible(true);
        pet[iPet].pet.setTransform(Sprite.TRANS_MIRROR);
        if (isTrailer) {
            if (pet[iPet].getX() < 50) {
                pet[iPet].pet.move(20, 0);
            } else {
                pet[iPet].pet.setPosition(50, this.getHeight() / 2 + this.getHeight() / 4 - pet[iPet].pet.getHeight() / 2);
            }
        } else {
            if (this.getWidth() >= 200) {
                pet[iPet].pet.setPosition(10, this.getHeight() / 2 + this.getHeight() / 4 - pet[iPet].pet.getHeight() / 2);
            } else {
                if (totalMemory >= 1000000) {
                    pet[iPet].pet.setPosition(5, myArena.getY() + myArena.getHeight() / 2 - pet[iPet].pet.getHeight() / 2);
                } else {
                    pet[iPet].pet.setPosition(5, 100 + 50 - pet[iPet].pet.getHeight() / 2);
                }
            }
        }
        if (this.getWidth() >= 200 || totalMemory >= 1000000) {
            doithuArena.setTransform(Sprite.TRANS_MIRROR);
            doithuArena.setPosition(0, 0);
            myArena.setPosition(0, doithuArena.getY() + doithuArena.getHeight());
        }
        if (this.getWidth() <= 200) {
            if (curYFight == 0) {
                listSkill.setPosition(listSkill.getX(), this.getHeight() - listSkill.getHeight());
            } else {
                listSkill.setPosition(listSkill.getX(), pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - listSkill.getHeight() / 2);
            }
        }
        addSkill.setPosition(listSkill.getX(), listSkill.getY());
        addSkill.fillCells(0, 0, listSkill.getColumns(), 1, 1);
        addSkill.fillCells(0, 1, listSkill.getColumns(), 1, 1);
        if (numberSkill <= 5) {
            addSkill.fillCells(0, 0, numberSkill, 1, 0);
        } else {
            addSkill.fillCells(0, 0, 5, 1, 0);
            addSkill.fillCells(0, 1, numberSkill - 5, 1, 0);
        }
        if (isYourTurn) {
            addSkill.setCell(1, 1, 1);
            addSkill.setCell(2, 1, 1);
            addSkill.setCell(4, 1, 1);
        } else {
            addSkill.fillCells(0, 0, listSkill.getColumns(), 1, 1);
            addSkill.setCell(0, 1, 1);
            addSkill.setCell(3, 1, 1);
        }
        if (!isWin && !isLose) {
            checkFight1(g);
        } else {
            if (isYourTurn) {
                if (oneHitPhandon.isVisible()) {
                    if (oneHitPhandon.getFrame() != oneHitPhandon.getFrameSequenceLength() - 1) {
                        oneHitPhandon.nextFrame();
                    } else {
                        curYFight = 0;
                        oneHitPhandon.setVisible(false);
                    }
                }
            } else {
                if (oneHitPhandon.isVisible()) {
                    if (oneHitPhandon.getFrame() != oneHitPhandon.getFrameSequenceLength() - 1) {
                        oneHitPhandon.nextFrame();
                    } else {
                        if (totalMemory > 1000000) {
                            curYFight = 2 * myArena.getHeight() - this.getHeight();
                        } else {
                            curYFight = 2 * 100 - this.getHeight();
                        }
                        oneHitPhandon.setVisible(false);
                    }
                }
            }
        }
        bottleHP.setVisible(true);
        bottleMP.setVisible(true);
        if (this.getWidth() >= 200 || totalMemory >= 1000000) {
            bottleHP.setPosition(this.getWidth() - 2 * (bottleMP.getWidth() + font1.stringWidth("x00")), myArena.getY() + 5);
            bottleMP.setPosition(this.getWidth() - 1 * (bottleMP.getWidth() + font1.stringWidth("x00")), myArena.getY() + 5);
        } else {
            bottleHP.setPosition(this.getWidth() - 2 * (bottleMP.getWidth() + font1.stringWidth("x00")), 100 + 5);
            bottleMP.setPosition(this.getWidth() - 1 * (bottleMP.getWidth() + font1.stringWidth("x00")), 100 + 5);
        }
        dtBottleHP.setVisible(true);
        dtBottleMP.setVisible(true);
        dtBottleMP.setPosition(5, 5);
        dtBottleHP.setPosition(dtBottleMP.getX() + dtBottleMP.getWidth() + font1.stringWidth("x00x"), 5);
        addSkill.setVisible(listSkill.isVisible());
//        lmFight.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        if (this.getWidth() >= 200) {
            curYFight = 0;
        }
        if (isShockScreen) {
            if (timeShock > 100) {
                lmFight.setViewWindow(curFightX + 1, 1 + curYFight, this.getWidth(), this.getHeight());
            }
            if (timeShock > 200) {
                lmFight.setViewWindow(curFightX - 1, -1 + curYFight, this.getWidth(), this.getHeight());
            }
            if (timeShock > 300) {
                lmFight.setViewWindow(curFightX + 1, 1 + curYFight, this.getWidth(), this.getHeight());
            }
            if (timeShock > 400) {
                lmFight.setViewWindow(curFightX - 1, -1 + curYFight, this.getWidth(), this.getHeight());
                isShockScreen = false;
                timeShock = 0;
            }
        } else {
            lmFight.setViewWindow(curFightX, curYFight, this.getWidth(), this.getHeight());
        }
        lmFight.paint(g, 0, 0);
        g.setColor(0xffffff);
        g.setFont(font2);
        if (isLose) {
            isDrawAnouceFight = true;
//            g.drawString("Bạn Thua!", this.getWidth() / 2, this.getHeight() / 2, Graphics.HCENTER | Graphics.BOTTOM);
            if (timeLose >= 2000) {
                timeLose = 0;
                isWin = false;
                isLose = false;
                isHitting = false;
                reHitting = false;
                isBeginFight = false;
                isMenuFight = false;
                if (this.getWidth() >= 200) {
                    myHPLine.setVisible(false);
                    myHpMp.setVisible(false);
                    doithuHPline.setVisible(false);
                    doithuHpMp.setVisible(false);
                }
                petDoiThu.pet.setVisible(false);
                if (this.getWidth() >= 200 || totalMemory > 1000000) {
                    myArena.setVisible(false);
                    doithuArena.setVisible(false);
                    if (this.getWidth() > 160) {
                        doithuWind.setVisible(false);
                        myWind.setVisible(false);
                    }
                }
                pet[iPet].pet.setVisible(false);
                bottleHP.setVisible(false);
                bottleMP.setVisible(false);
                dtBottleHP.setVisible(false);
                dtBottleMP.setVisible(false);
                buffSkill.setVisible(false);
                face.setVisible(false);
//                money -= infoDoithu[iChooseFight][6];
                pet[iPet].mp = maxMPMe;
                pet[iPet].hp = maxHPMe;
                petDoiThu.mp = maxMPDoiThu;
                petDoiThu.hp = maxHPDoiThu;
                listSkill.setVisible(false);
                isDrawAnouceFight = false;
                face.setVisible(false);
                if (addMainScreen != null) {
                    addMainScreen.setVisible(false);
                }
                if (addNenFight != null) {
                    addNenFight.setVisible(false);
                }
                isMenuFight = true;
                doithuBuffSkill.setVisible(false);
                isPresentKey = false;
//                iMenuFight = 3;
//                menuFightPressed();
            }
        }
        if (isWin) {
            isDrawAnouceFight = true;
//            g.drawString("Bạn Thắng !", this.getWidth() / 2, this.getHeight() / 2, Graphics.HCENTER | Graphics.BOTTOM);
            if (timeWin >= 2000) {
                timeWin = 0;
                isWin = false;
                isHitting = false;
                reHitting = false;
                isBeginFight = false;
                isMenuFight = false;
                if (myHPLine != null) {
                    myHPLine.setVisible(false);
                    myHpMp.setVisible(false);
                    doithuHPline.setVisible(false);
                    doithuHpMp.setVisible(false);
                }
                petDoiThu.pet.setVisible(false);
                if (this.getWidth() >= 200 || totalMemory > 1000000) {
                    myArena.setVisible(false);
                    doithuArena.setVisible(false);
                    if (this.getWidth() > 160) {
                        doithuWind.setVisible(false);
                        myWind.setVisible(false);
                    }
                }
                pet[iPet].pet.setVisible(false);
                bottleHP.setVisible(false);
                bottleMP.setVisible(false);
                dtBottleHP.setVisible(false);
                dtBottleMP.setVisible(false);
                buffSkill.setVisible(false);
                face.setVisible(false);
//                money += infoDoithu[iChooseFight][6];
                pet[iPet].mp = maxMPMe;
                pet[iPet].hp = maxHPMe;
                petDoiThu.mp = maxMPDoiThu;
                petDoiThu.hp = maxHPDoiThu;
                listSkill.setVisible(false);
                face.setVisible(false);
                isDrawAnouceFight = false;
                if (addMainScreen != null) {
                    addMainScreen.setVisible(false);
                }
                if (addNenFight != null) {
                    addNenFight.setVisible(false);
                }
                isMenuFight = true;
                doithuBuffSkill.setVisible(false);
                isPresentKey = false;
//                iMenuFight = 3;
//                menuFightPressed();
            }
        }
        if (totalMemory < 1000000 && this.getWidth() < 160) {
            g.setColor(0xffffff);
            if (curYFight == 0) {
                g.drawLine(0, 100, this.getWidth(), 100);
            } else {
                g.drawLine(0, 200 - this.getHeight(), this.getWidth(), 200 - this.getHeight());
            }
        }
        if (isYourTurn) {
            if (!isTrailer && !isHitting && timeWaitChooseSkill >= 0) {
                g.setColor(0xff0000);
                g.setFont(font1);
                String str1 = "Time: " + timeWaitChooseSkill / 1000;
                g.drawString(str1, listSkill.getX(), listSkill.getY() + listSkill.getHeight() - curYFight, Graphics.LEFT | Graphics.TOP);
            }
        }
        if (timeDrawYourTurn < 2000) {
            if (!isTrailer && !isLose && !isWin) {
                g.setColor(0x000000);
                if (this.getWidth() > 200) {
                    g.fillRect(0, myArena.getY() - 30 - curYFight, this.getWidth(), 30);
                } else {
                    if (totalMemory > 1000000) {
                        g.fillRect(0, myArena.getY() - 30 - curYFight, this.getWidth(), 30);
                    } else {
                        g.fillRect(0, 100 - 30 - curYFight, this.getWidth(), 30);
                    }
                }
                g.setColor(0xffffff);
                if (isYourTurn) {
                    if (this.getWidth() >= 200) {
                        String str1 = "Phím 1, 3 để bơm máu và MP";
                        byte[] text = new byte[str1.length()];
                        Designer.toBytesIndex(str1, text);
                        Designer.drawString(g, text, 0, str1.length(), Designer.FONT_TEXT, 11, this.getWidth() / 2 - Designer.getStringWidth(text, 0, str1.length(), Designer.FONT_TEXT) / 2, myArena.getY() - 30 - curYFight);
                    } else {
                        if (totalMemory >= 1000000) {
                            String str1 = "Phím 1, 3 để bơm máu và MP";
                            byte[] text = new byte[str1.length()];
                            Designer.toBytesIndex(str1, text);
                            Designer.drawString(g, text, 0, str1.length(), Designer.FONT_TEXT, 11, this.getWidth() / 2 - Designer.getStringWidth(text, 0, str1.length(), Designer.FONT_TEXT) / 2, myArena.getY() - 30 - curYFight);
                        } else {
                            g.drawString("Phím 1, 3 để bơm máu & MP", this.getWidth() / 2, 100 - 30 - curYFight, Graphics.TOP | Graphics.HCENTER);
                        }
                    }
                    g.setFont(font1);
                    if (this.getWidth() >= 200) {
                        g.drawString("Lượt của bạn !", this.getWidth() / 2, myArena.getY() - curYFight, Graphics.HCENTER | Graphics.BOTTOM);
                    } else {
                        if (totalMemory > 1000000) {
                            g.drawString("Lượt của bạn !", this.getWidth() / 2, myArena.getY() - curYFight, Graphics.HCENTER | Graphics.BOTTOM);
                        } else {
                            g.drawString("Lượt của bạn !", this.getWidth() / 2, 100 - curYFight, Graphics.HCENTER | Graphics.BOTTOM);
                        }
                    }
                } else {
                    g.setFont(font1);
                    if (mana[iSkill] > pet[iPet].mp) {
                        g.setColor(0xff0000);
                        g.drawString("Không đủ MP", this.getWidth() / 2, this.getHeight() / 2 - 30 - curYFight, Graphics.TOP | Graphics.HCENTER);
                    }
                    g.setColor(0xffffff);
                    if (this.getWidth() >= 200) {
                        g.drawString("Lượt của đối thủ !", this.getWidth() / 2, myArena.getY() - curYFight, Graphics.HCENTER | Graphics.BOTTOM);
                    } else {
                        if (totalMemory > 1000000) {
                            g.drawString("Lượt của đối thủ !", this.getWidth() / 2, myArena.getY() - curYFight, Graphics.HCENTER | Graphics.BOTTOM);
                        } else {
                            g.drawString("Lượt của đối thủ !", this.getWidth() / 2, 100 - curYFight, Graphics.HCENTER | Graphics.BOTTOM);
                        }
                    }
                }
            }
        }
        if (totalMemory >= 1000000 || this.getWidth() >= 200) {
            try {
                if (isTrailer) {
                    g.drawImage(gameDesign.getVS(), this.getWidth() / 2, this.getHeight() / 2, Graphics.HCENTER | Graphics.VCENTER);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            if (isTrailer) {
                g.setColor(0xff0000);
                g.drawString("VS", this.getWidth() / 2, this.getHeight() / 2, Graphics.HCENTER | Graphics.BOTTOM);
            }
        }
        if (this.getWidth() >= 200) {
            g.setColor(87, 87, 87);
            g.fillRect(doithuHPline.getX() + 1, doithuHPline.getY() + 1, (maxHPDoiThu - petDoiThu.hp) * doithuHPline.getWidth() / maxHPDoiThu, doithuHPline.getCellHeight() - 2);
            g.fillRect(doithuHPline.getX() + 1, doithuHPline.getY() + doithuHPline.getCellHeight() + 1, (maxMPDoiThu - petDoiThu.mp) * doithuHPline.getWidth() / maxMPDoiThu, doithuHPline.getCellHeight() - 2);
            g.fillRect(myHPLine.getX() + myHPLine.getWidth() - (maxHPMe - pet[iPet].hp) * myHPLine.getWidth() / maxHPMe - 1, myHPLine.getY() + 1, (maxHPMe - pet[iPet].hp) * myHPLine.getWidth() / maxHPMe, myHPLine.getCellHeight() - 2);
            g.fillRect(myHPLine.getX() + myHPLine.getWidth() - (maxMPMe - pet[iPet].mp) * myHPLine.getWidth() / maxMPMe - 1, myHPLine.getY() + myHPLine.getCellHeight() + 1, (maxMPMe - pet[iPet].mp) * myHPLine.getWidth() / maxMPMe, myHPLine.getCellHeight() - 2);
        }
        g.setColor(0xff0000);
//        g.drawLine(0, this.getHeight() / 2, this.getWidth(), this.getHeight() / 2);
        g.setFont(font1);
        if (listSkill.isVisible()) {
            if (iSkill < 5) {
                g.drawRoundRect(listSkill.getX() + iSkill * listSkill.getCellWidth() - 1, listSkill.getY() - 1 - curYFight, listSkill.getCellWidth() + 2, listSkill.getCellHeight() + 2, 5, 5);
            } else {
                g.drawRoundRect(listSkill.getX() + (iSkill - 5) * listSkill.getCellWidth() - 1, listSkill.getY() - 1 + listSkill.getCellHeight() - curYFight, listSkill.getCellWidth() + 2, listSkill.getCellHeight() + 2, 5, 5);
            }
        }
        g.setColor(0xff0000);
        if (this.getWidth() >= 200) {
            if (!isTrailer) {
                g.drawString("Level :" + pet[iPet].level, myHPLine.getX(), myHPLine.getY() + myHPLine.getHeight() + 5, Graphics.TOP | Graphics.LEFT);
                g.drawString("Level :" + petDoiThu.level, doithuHPline.getX(), doithuHPline.getY() + doithuHPline.getHeight() + 5, Graphics.TOP | Graphics.LEFT);
            }
        }
        if (isDrawAnouceFight) {
            drawAnouceFight(g);
        }
        if (!isMssFight) {
            if (this.getWidth() >= 200) {
                if (listSkill.isVisible() && !isDrawAnouceFight) {
                    g.setColor(0x000000);
                    g.fillRect(0, this.getHeight() - 30, this.getWidth(), 30);
                    g.setColor(0xffffff);
                    g.drawString(skillName[iSkill], this.getWidth() / 2, this.getHeight() - 30, Graphics.HCENTER | Graphics.TOP);
                    g.drawString("MP:" + mana[iSkill] + "  Acc:" + acc[iSkill], this.getWidth() / 2, this.getHeight() - 30 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                }
            }
            if (!isDrawAnouceFight) {
                fillRectPointerPressed(g);
                g.setColor(0x0000ff);
                g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            }
        } else {
            fillRectPointerPressed(g);
            g.setColor(0, 128, 192);
            g.fillRoundRect(this.getWidth() / 2 - font1.stringWidth("Bạn có muốn thoát ?") / 2 - 5, this.getHeight() - 10 - 5 * font1.getHeight() / 2, font1.stringWidth("Bạn có muốn thoát ?") + 10, font1.getHeight() + 10, 6, 6);
            g.setColor(0x0000ff);
            g.drawString("Bạn có muốn thoát ?", this.getWidth() / 2, this.getHeight() - 5 - 5 * font1.getHeight() / 2, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Bỏ qua", this.getWidth(), this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
            g.drawString("Đồng ý", 0, this.getHeight(), Graphics.BOTTOM | Graphics.LEFT);
        }
        if (!isTrailer && !isDrawAnouceFight) {
            String str = "x" + noBottleHP;
            byte[] text = new byte[str.length()];
            if (this.getWidth() >= 200) {
                str = "x" + noBottleHP;
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, bottleHP.getX() + bottleHP.getWidth(), bottleHP.getY() - curYFight);
                str = "x" + noBottleMP;
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, bottleMP.getX() + bottleMP.getWidth(), bottleMP.getY() - curYFight);
            } else {
                if (curYFight != 0) {
                    str = "x" + noBottleHP;
                    g.drawString(str, bottleHP.getX() + bottleHP.getWidth(), bottleHP.getY() - curYFight, Graphics.TOP | Graphics.LEFT);
                    str = "x" + noBottleMP;
                    g.drawString(str, bottleMP.getX() + bottleMP.getWidth(), bottleMP.getY() - curYFight, Graphics.TOP | Graphics.LEFT);
                }
            }
            if (this.getWidth() >= 200) {
                str = Integer.toString(pet[iPet].hp);
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, myHPLine.getX() + myHPLine.getWidth(), myHPLine.getY() - (15 - myHPLine.getCellHeight()) / 2);
                str = Integer.toString(pet[iPet].mp);
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, myHPLine.getX() + myHPLine.getWidth(), myHPLine.getY() + myHPLine.getCellHeight() - (15 - myHPLine.getCellHeight()) / 2);
                str = Integer.toString(petDoiThu.hp);
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, doithuHPline.getX() - str.length() * 6, doithuHPline.getY() - (15 - myHPLine.getCellHeight()) / 2);
                str = Integer.toString(petDoiThu.mp);
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, doithuHPline.getX() - str.length() * 6, doithuHPline.getY() + myHPLine.getCellHeight() - (15 - myHPLine.getCellHeight()) / 2);
            } else {
                g.setColor(0xff0000);
                g.setFont(font1);
                if (this.getWidth() > 200) {
                    if (curYFight == 2 * myArena.getHeight() - this.getHeight()) {
                        g.drawString("HP : " + pet[iPet].hp, 0, this.getHeight() - myArena.getHeight(), Graphics.LEFT | Graphics.TOP);
                        g.drawString("MP : " + pet[iPet].mp, 0, this.getHeight() - myArena.getHeight() + font1.getHeight(), Graphics.LEFT | Graphics.TOP);
                    } else {
                        g.drawString("HP : " + petDoiThu.hp, this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                        g.drawString("MP : " + petDoiThu.mp, this.getWidth(), font1.getHeight(), Graphics.RIGHT | Graphics.TOP);
                    }
                } else {
                    if (totalMemory > 1000000) {
                        if (curYFight == 2 * myArena.getHeight() - this.getHeight()) {
                            g.drawString("HP : " + pet[iPet].hp, 0, this.getHeight() - myArena.getHeight(), Graphics.LEFT | Graphics.TOP);
                            g.drawString("MP : " + pet[iPet].mp, 0, this.getHeight() - myArena.getHeight() + font1.getHeight(), Graphics.LEFT | Graphics.TOP);
                        } else {
                            g.drawString("HP : " + petDoiThu.hp, this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                            g.drawString("MP : " + petDoiThu.mp, this.getWidth(), font1.getHeight(), Graphics.RIGHT | Graphics.TOP);
                        }
                    } else {
                        if (curYFight == 200 - this.getHeight()) {
                            g.drawString("HP : " + pet[iPet].hp, 0, this.getHeight() - 100, Graphics.LEFT | Graphics.TOP);
                            g.drawString("MP : " + pet[iPet].mp, 0, this.getHeight() - 100 + font1.getHeight(), Graphics.LEFT | Graphics.TOP);
                        } else {
                            g.drawString("HP : " + petDoiThu.hp, this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
                            g.drawString("MP : " + petDoiThu.mp, this.getWidth(), font1.getHeight(), Graphics.RIGHT | Graphics.TOP);
                        }
                    }
                }
            }
        }
        if (!isTrailer && !isDrawAnouceFight) {
            if (this.getWidth() >= 200) {
                String str = "x" + doithuBottleMP;
                byte[] text = new byte[str.length()];
                str = "x" + doithuBottleMP;
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, dtBottleMP.getX() + dtBottleMP.getWidth(), 5);
                str = "x" + doithuBottleHP;
                text = new byte[str.length()];
                Designer.toBytesIndex(str, text);
                Designer.drawString(g, text, 0, str.length(), Designer.FONT_TEXT, 11, dtBottleHP.getX() + dtBottleHP.getWidth(), 5);
                g.setColor(0xff0000);
//                g.drawString("x" + doithuBottleMP, dtBottleMP.getX() + dtBottleMP.getWidth(), 5, Graphics.TOP | Graphics.LEFT);
//                g.drawString("x" + doithuBottleHP, dtBottleHP.getX() + dtBottleHP.getWidth(), 5, Graphics.TOP | Graphics.LEFT);
            } else {
                if (curYFight == 0) {
                    g.setColor(0xff0000);
                    g.drawString("x" + doithuBottleMP, dtBottleMP.getX() + dtBottleMP.getWidth(), 5, Graphics.TOP | Graphics.LEFT);
                    g.drawString("x" + doithuBottleHP, dtBottleHP.getX() + dtBottleHP.getWidth(), 5, Graphics.TOP | Graphics.LEFT);
                }
            }
        }
        if (isBomMau) {
            g.drawRoundRect(bottleHP.getX(), bottleHP.getY(), bottleHP.getWidth(), bottleHP.getHeight(), 3, 3);
        }
        if (isBomMP) {
            g.drawRoundRect(bottleMP.getX(), bottleMP.getY(), bottleMP.getWidth(), bottleMP.getHeight(), 3, 3);
        }
        flushGraphics();
    }

    public void drawChooseEgg(Graphics g) {
        g.setColor(2, 140, 253);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        g.setColor(0xffffff);
        if (iEgg == 0) {
            g.drawRoundRect(this.getWidth() / 4 - egg1.getWidth() / 2 - 5 - 2, this.getHeight() / 2 - egg1.getHeight() / 2 - 2, egg1.getWidth() + 15 + 3, egg1.getHeight() + 3, 5, 5);
        } else {
            g.drawRoundRect(3 * this.getWidth() / 4 - egg2.getWidth() / 2 - 5 - 2, this.getHeight() / 2 - egg2.getHeight() / 2 - 2, egg2.getWidth() + 15 + 3, egg2.getHeight() + 3, 5, 5);
        }
        g.setColor(1, 80, 126);
        g.fillRoundRect(this.getWidth() / 4 - egg1.getWidth() / 2 - 5, this.getHeight() / 2 - egg1.getHeight() / 2, egg1.getWidth() + 15, egg1.getHeight(), 5, 5);
        g.fillRoundRect(3 * this.getWidth() / 4 - egg1.getWidth() / 2 - 5, this.getHeight() / 2 - egg1.getHeight() / 2, egg1.getWidth() + 15, egg1.getHeight(), 5, 5);
        lmChooseEgg.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lmChooseEgg.paint(g, 0, 0);
        fillRectPointerPressed(g);
        g.setColor(0xffffff);
        g.setFont(font1);
        g.drawString("Giá : 500$", this.getWidth() / 2, this.getHeight() / 4, Graphics.HCENTER | Graphics.BOTTOM);
        g.drawString("Gà lửa", egg1.getX() + egg1.getWidth() / 2, egg1.getY() + egg1.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
        g.drawString("???", egg2.getX() + egg2.getWidth() / 2, egg1.getY() + egg1.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
        g.drawString("OK", this.getWidth() / 2, this.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
        g.drawString("Trở về", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
        g.drawString("Tiền :" + money + "$", this.getWidth(), 5 + font2.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
        if (money < 500) {
            g.setColor(0xff0000);
            g.drawString("Không đủ tiền !", this.getWidth() / 2, this.getHeight() / 2 + egg1.getHeight() / 2 + 10 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        }
        flushGraphics();
    }

    public void drawChoosePet(Graphics g) {
        g.setColor(2, 140, 253);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        int height, height1, height2;
        if (pet[0] != null) {
            height1 = pet[0].pet.getHeight() + 5 + font1.getHeight() * 6;
        } else {
            height1 = 40 + 5 + font1.getHeight() * 6;
        }
        if (pet[1] != null) {
            height2 = pet[1].pet.getHeight() + 5 + font1.getHeight() * 6;
        } else {
            height2 = 40 + 5 + font1.getHeight() * 6;
        }
        height = Math.max(height1, height2);
        int width = this.getWidth() / 2 - 10;
        g.setColor(1, 80, 126);
        g.fillRect(0, this.getHeight() / 2 - height / 2 - 20, this.getWidth(), height + 40);
        if (iChoosePet == 0) {
            g.setColor(0xffff00);
            g.drawRoundRect(this.getWidth() / 4 - width / 2, this.getHeight() / 2 - height / 2 - 5, width, height + 10, 5, 5);
            g.drawRoundRect(this.getWidth() / 4 - width / 2 - 2, this.getHeight() / 2 - height / 2 - 5 - 2, width + 4, height + 10 + 4, 5, 5);
            g.setColor(0xffffff);
            g.drawRoundRect(3 * this.getWidth() / 4 - width / 2, this.getHeight() / 2 - height / 2 - 5, width, height + 10, 5, 5);
        } else {
            g.setColor(0xffff00);
            g.drawRoundRect(3 * this.getWidth() / 4 - width / 2, this.getHeight() / 2 - height / 2 - 5, width, height + 10, 5, 5);
            g.drawRoundRect(3 * this.getWidth() / 4 - width / 2 - 2, this.getHeight() / 2 - height / 2 - 5 - 2, width + 4, height + 10 + 4, 5, 5);
            g.setColor(0xffffff);
            g.drawRoundRect(this.getWidth() / 4 - width / 2, this.getHeight() / 2 - height / 2 - 5, width, height + 10, 5, 5);
        }
        g.setColor(0xffffff);
        if (!midlet.infoPet1.isChosenPet) {
            g.setFont(font3);
            g.drawString("Tạo thú nuôi", this.getWidth() / 4, this.getHeight() / 2 - height / 2, Graphics.HCENTER | Graphics.TOP);
            g.drawString("500$", this.getWidth() / 4, this.getHeight() / 2 - height / 2 + font3.getHeight(), Graphics.HCENTER | Graphics.TOP);
        } else {
            g.setFont(font1);
            if (pet[0].level > 2) {
                pet[0].chickMove();
            }
            pet[0].pet.setVisible(true);
            pet[0].setPosition(this.getWidth() / 4 - pet[0].pet.getWidth() / 2, this.getHeight() / 2 - height / 2 - 5);
            g.drawString(pet[0].title, this.getWidth() / 4, pet[0].getY() + pet[0].pet.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Level :" + pet[0].level, this.getWidth() / 4, pet[0].getY() + pet[0].pet.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Exp :" + pet[0].exp, this.getWidth() / 4, pet[0].getY() + pet[0].pet.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Kĩ năng :" + pet[0].skillPoint, this.getWidth() / 4, pet[0].getY() + pet[0].pet.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("HP :" + pet[0].hp, this.getWidth() / 4, pet[0].getY() + pet[0].pet.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("MP :" + pet[0].mp, this.getWidth() / 4, pet[0].getY() + pet[0].pet.getHeight() + 5 + 5 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        }
        if (!midlet.infoPet2.isChosenPet) {
            g.setFont(font3);
            g.drawString("Tạo thú nuôi", 3 * this.getWidth() / 4, this.getHeight() / 2 - height / 2, Graphics.HCENTER | Graphics.TOP);
            g.drawString("500$", 3 * this.getWidth() / 4, this.getHeight() / 2 - height / 2 + font3.getHeight(), Graphics.HCENTER | Graphics.TOP);
        } else {
            if (pet[1].getState() > 2) {
                pet[1].chickMove();
            }
            g.setFont(font1);
            pet[1].pet.setVisible(true);
            pet[1].setPosition(3 * this.getWidth() / 4 - pet[1].pet.getWidth() / 2, this.getHeight() / 2 - height / 2 - 5);
            g.drawString(pet[1].title, 3 * this.getWidth() / 4, pet[1].getY() + pet[1].pet.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            g.drawString("Level :" + pet[1].level, 3 * this.getWidth() / 4, pet[1].getY() + pet[1].pet.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Exp :" + pet[1].exp, 3 * this.getWidth() / 4, pet[1].getY() + pet[1].pet.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("Kĩ năng :" + pet[1].skillPoint, 3 * this.getWidth() / 4, pet[1].getY() + pet[1].pet.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("HP :" + pet[1].hp, 3 * this.getWidth() / 4, pet[1].getY() + pet[1].pet.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            g.drawString("MP :" + pet[1].mp, 3 * this.getWidth() / 4, pet[1].getY() + pet[1].pet.getHeight() + 5 + 5 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
        }
        if (!isExitGamePressed && !isSellPet) {
            fillRectPointerPressed(g);
            g.drawString("Thoát", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
            if ((iChoosePet == 0 && midlet.infoPet1.isChosenPet) || (iChoosePet == 1 & midlet.infoPet2.isChosenPet)) {
                g.drawString("Bán", 0, this.getHeight(), Graphics.LEFT | Graphics.BOTTOM);
            }
        } else {
            fillRectPointerPressed(g);
            g.drawString("Bỏ qua", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
            g.drawString("Đồng ý", 0, this.getHeight(), Graphics.LEFT | Graphics.BOTTOM);
            if (isExitGamePressed) {
                g.drawString("Bạn có muốn thoát game ?", this.getWidth() / 2, this.getHeight() - 2 * font1.getHeight() - 5, Graphics.HCENTER | Graphics.TOP);
            }
            if (isSellPet) {
                g.drawString("Bạn sẽ thu được " + pet[iPet].cost + "$", this.getWidth() / 2, this.getHeight() - 3 * font1.getHeight() - 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("Bạn có muốn bán thú nuôi ?", this.getWidth() / 2, this.getHeight() - 2 * font1.getHeight() - 5, Graphics.HCENTER | Graphics.TOP);
            }
        }
        g.drawString("Tiền :" + money + "$", this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
        if (!isExitGamePressed && !isSellPet) {
            fillRectPointerPressed(g);
            g.drawString("OK", this.getWidth() / 2, this.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
        }
//        if (money < 500) {
//            g.setColor(0xff0000);
//            if (this.getWidth() > 200) {
//                g.drawString("Không đủ tiền !", this.getWidth() / 2, font3.getHeight(), Graphics.HCENTER | Graphics.TOP);
//            } else {
//                g.drawString("Không đủ tiền !", this.getWidth() / 2, this.getHeight() / 2, Graphics.HCENTER | Graphics.TOP);
//            }
//        }
        lmChoosePet.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lmChoosePet.paint(g, 0, 0);
        flushGraphics();
    }

    public void drawChoosePet128(Graphics g) {
        g.setColor(2, 140, 253);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        int height = 0;
        if (pet[iPet] == null) {
            height = 25 + 5 + font1.getHeight() * 6;
        } else {
            height = pet[iPet].pet.getHeight() + 5 + font1.getHeight() * 6;
        }
        int width = this.getWidth() - 2 * font1.stringWidth("< ");
        g.setColor(0xffff00);
        g.setFont(font1);
        g.drawRoundRect(this.getWidth() / 2 - width / 2, font1.getHeight() + 3, width, height + 4, 5, 5);
        g.setColor(0xffffff);
        if (iChoosePet == 0) {
            if (pet[0] != null) {
                pet[0].pet.setVisible(true);
            }
            if (pet[1] != null) {
                pet[1].pet.setVisible(false);
            }
            if (!midlet.infoPet1.isChosenPet) {
                g.drawString("Tạo thú nuôi 1", this.getWidth() / 2, font1.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("500$", this.getWidth() / 2, 2 * font1.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            } else {
                if (pet[0].getState() == Pet.STATE_CHICK_SMALL) {
                    pet[0].chickMove();
                }
                pet[0].pet.setVisible(true);
                pet[0].setPosition(this.getWidth() / 2 - pet[0].pet.getWidth() / 2, font1.getHeight() + 5);
                g.drawString(pet[0].title, this.getWidth() / 2, pet[0].getY() + pet[0].pet.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("Level :" + pet[0].level, this.getWidth() / 2, pet[0].getY() + pet[0].pet.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Exp :" + pet[0].exp, this.getWidth() / 2, pet[0].getY() + pet[0].pet.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Kĩ năng :" + pet[0].skillPoint, this.getWidth() / 2, pet[0].getY() + pet[0].pet.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("HP :" + pet[0].hp, this.getWidth() / 2, pet[0].getY() + pet[0].pet.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("MP :" + pet[0].mp, this.getWidth() / 2, pet[0].getY() + pet[0].pet.getHeight() + 5 + 5 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            }
        }
        if (iChoosePet == 1) {
            if (pet[0] != null) {
                pet[0].pet.setVisible(false);
            }
            if (pet[1] != null) {
                pet[1].pet.setVisible(true);
            }
            if (!midlet.infoPet2.isChosenPet) {
                g.drawString("Tạo thú nuôi 2", this.getWidth() / 2, font1.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("500$", this.getWidth() / 2, 2 * font1.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
            } else {
                if (pet[1].getState() == Pet.STATE_CHICK_SMALL) {
                    pet[1].chickMove();
                }
                pet[1].pet.setVisible(true);
                pet[1].setPosition(this.getWidth() / 2 - pet[1].pet.getWidth() / 2, font1.getHeight() + 5);
                g.drawString(pet[1].title, this.getWidth() / 2, pet[1].getY() + pet[1].pet.getHeight() + 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("Level :" + pet[1].level, this.getWidth() / 2, pet[1].getY() + pet[1].pet.getHeight() + 5 + font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Exp :" + pet[1].exp, this.getWidth() / 2, pet[1].getY() + pet[1].pet.getHeight() + 5 + 2 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("Kĩ năng :" + pet[1].skillPoint, this.getWidth() / 2, pet[1].getY() + pet[1].pet.getHeight() + 5 + 3 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("HP :" + pet[1].hp, this.getWidth() / 2, pet[1].getY() + pet[1].pet.getHeight() + 5 + 4 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
                g.drawString("MP :" + pet[1].mp, this.getWidth() / 2, pet[1].getY() + pet[1].pet.getHeight() + 5 + 5 * font1.getHeight(), Graphics.HCENTER | Graphics.TOP);
            }
        }
        g.drawString("<", 0, this.getHeight() / 2, Graphics.BOTTOM | Graphics.LEFT);
        g.drawString(">", this.getWidth(), this.getHeight() / 2, Graphics.BOTTOM | Graphics.RIGHT);
        if (!isExitGamePressed && !isSellPet) {
            fillRectPointerPressed(g);
            g.drawString("Thoát", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
            if ((iChoosePet == 0 && midlet.infoPet1.isChosenPet) || (iChoosePet == 1 & midlet.infoPet2.isChosenPet)) {
                g.drawString("Bán", 0, this.getHeight(), Graphics.LEFT | Graphics.BOTTOM);
            }
        } else {
            fillRectPointerPressed(g);
            g.setColor(0x000000);
            g.fillRect(0, this.getHeight() - 7 * font1.getHeight() / 2, this.getWidth(), 7 * font1.getHeight() / 2);
            g.setColor(0xffffff);
            g.drawString("Bỏ qua", this.getWidth(), this.getHeight(), Graphics.RIGHT | Graphics.BOTTOM);
            g.drawString("Đồng ý", 0, this.getHeight(), Graphics.LEFT | Graphics.BOTTOM);
            if (isExitGamePressed) {
                g.setColor(0xffffff);
                g.drawString("Bạn có muốn thoát game ?", this.getWidth() / 2, this.getHeight() - 2 * font1.getHeight() - 5, Graphics.HCENTER | Graphics.TOP);
            }
            if (isSellPet) {
                g.setColor(0xffffff);
                g.drawString("Bạn sẽ thu được " + pet[iPet].cost + "$", this.getWidth() / 2, this.getHeight() - 3 * font1.getHeight() - 5, Graphics.HCENTER | Graphics.TOP);
                g.drawString("Bạn có muốn bán thú nuôi ?", this.getWidth() / 2, this.getHeight() - 2 * font1.getHeight() - 5, Graphics.HCENTER | Graphics.TOP);
            }
        }
        g.drawString("Tiền :" + money + "$", this.getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
        if (!isExitGamePressed && !isSellPet) {
            fillRectPointerPressed(g);
            g.drawString("OK", this.getWidth() / 2, this.getHeight(), Graphics.HCENTER | Graphics.BOTTOM);
        }
        lmChoosePet.setViewWindow(0, 0, this.getWidth(), this.getHeight());
        lmChoosePet.paint(g, 0, 0);
        flushGraphics();
    }

    public void checkFight1(Graphics g) {
        if (isYourTurn) {
            if (time1kChooseSkill >= 1000) {
                if (pet[iPet].mp < maxMPMe) {
                    pet[iPet].mp += 1;
                }
                if (pet[iPet].hp < maxHPMe) {
                    pet[iPet].hp += 1;
                }
                if (pet[iPet].mp < maxMPDoiThu) {
                    petDoiThu.mp += 1;
                }
                if (pet[iPet].hp < maxHPDoiThu) {
                    petDoiThu.hp += 1;
                }
                time1kChooseSkill = 0;
            }
            if (timeWaitChooseSkill <= 0) {
                iSkill = 0;
                pet[iPet].mp -= 0;
                try {
                    if (this.getWidth() >= 160) {
                        hit.setImage(gameDesign.getGa_skill1(), 60, 60);
                    } else {
                        hit.setImage(gameDesign.getGa_skill1128(), 40, 40);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                int[] seq = {0, 1, 2};
                hit.setFrameSequence(seq);
                hit.setVisible(false);
                pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq001);
                checkAfterChooseSkill();
            }
        }
        if (isYourTurn && !isHitting) {
            listSkill.setVisible(!isTrailer);
            if (this.getWidth() >= 200) {
                listSkill.setPosition(pet[iPet].pet.getX() + pet[iPet].pet.getWidth() + 10, 3 * this.getHeight() / 4 - listSkill.getHeight() / 2);
            } else {
                listSkill.setPosition(pet[iPet].pet.getX() + pet[iPet].pet.getWidth(), pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - listSkill.getHeight() / 2);
            }
        }
        if (buffSkill.isVisible()) {
            buffSkill.nextFrame();
        }
        if (doithuBuffSkill.isVisible()) {
            doithuBuffSkill.nextFrame();
        }
        if (isYourTurn) {
            if (isHitting) {
                checkMyPetCreatHit();
                checkMyHit();
                checkMyPetOneHit();
                checkDoiThuTrungdon();
                if (oneHitPhandon.isVisible()) {
                    if (oneHitPhandon.getFrame() != oneHitPhandon.getFrameSequenceLength() - 1) {
                        oneHitPhandon.nextFrame();
                    } else {
                        curYFight = 0;
                        oneHitPhandon.setVisible(false);
                        checkHit();
                    }
                }
            }
        } else {
            if (reHitting) {
                checkDoiThuCreatHit();
                checkDoiThuHit();
                checkDoiThuOneHit();
                checkMyPetTrungdon();
                if (oneHitPhandon.isVisible()) {
                    if (oneHitPhandon.getFrame() != oneHitPhandon.getFrameSequenceLength() - 1) {
                        oneHitPhandon.nextFrame();
                    } else {
                        if (totalMemory > 1000000) {
                            curYFight = 2 * myArena.getHeight() - this.getHeight();
                        } else {
                            curYFight = 2 * 100 - this.getHeight();
                        }
                        oneHitPhandon.setVisible(false);
                        checkHit();
                    }
                }
            }
        }
    }

    public void checkMyPetCreatHit() {
        if (isAttack) {
            if (pet[iPet].pet.getFrame() < 6) {
                if (pet[iPet].pet.getFrame() != 5) {
                    pet[iPet].pet.nextFrame();
                    if (iSkill == 4) {
                        if (pet[iPet].pet.getFrame() == 2 || pet[iPet].pet.getFrame() == 3) {
                            pet[iPet].pet.setPosition(pet[iPet].getX(), this.getHeight() / 2 + this.getHeight() / 4 - pet[iPet].pet.getHeight() / 2 - 15);
                        } else {
                            pet[iPet].pet.setPosition(pet[iPet].getX(), this.getHeight() / 2 + this.getHeight() / 4 - pet[iPet].pet.getHeight() / 2);
                        }
                    }
                } else {
                    isAttack = false;
                    if (iSkill != 5) {
                        hit.setVisible(true);
                    }
                    if (iSkill == 5) {
                        isWaitHit6 = true;
                    }
                    if (iSkill == 4 || iSkill == 5) {
                        isShockScreen = true;
                        midlet.display.vibrate(500);
                    }
                }
            }
        }
    }

    public void checkMyHit() {
        if (iSkill == 5) {
            if (timeHitSkill6 >= 1000) {
                if (!isReSkill8) {
                    if (!isReSkill7) {
                        hit.setVisible(true);
                        petDoiThu.pet.setFrame(36);
                        pet[iPet].pet.setFrame(0);
                    } else {
                        if (this.getWidth() > 160) {
                            myWind.setVisible(false);
                            doithuWind.setVisible(false);
                            addNenFight.setVisible(false);
                        }
                        timeHitSkill6 = 0;
                        isWaitHit6 = false;
                        doithuBuffSkill.setVisible(false);
                        if (dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend > 0) {
                            pet[iPet].hp -= dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend;
                        }
                        myPet0Hp();
                        oneHitPhandon.setVisible(true);
                        oneHitPhandon.setPosition(pet[iPet].getX() - (oneHitPhandon.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (oneHitPhandon.getHeight() - pet[iPet].pet.getHeight()) / 2);
                        oneHitPhandon.setFrame(0);
                        isReSkill7 = false;
                    }
                } else {
                    if (this.getWidth() > 160) {
                        myWind.setVisible(false);
                        doithuWind.setVisible(false);
                        addNenFight.setVisible(false);
                    }
                    timeHitSkill6 = 0;
                    isWaitHit6 = false;
                    doithuBuffSkill.setVisible(false);
                    if (isReSkill10) {
                        doithuBuffSkill.setVisible(false);
                    }
                    checkHit();
                }
                if (isMySkill9) {
                    buffSkill.setVisible(false);
                }
            }
            if (hit.isVisible()) {
                curYFight = 0;
                if (hit.getFrame() != hit.getFrameSequenceLength() - 1) {
                    hit.nextFrame();
                } else {
                    timeHitSkill6 = 0;
                    isWaitHit6 = false;
                    hit.setFrame(hit.getFrameSequenceLength() - 1);
                    if (this.getWidth() > 160) {
                        myWind.setVisible(false);
                        doithuWind.setVisible(false);
                        addNenFight.setVisible(false);
                    }
                    if (isMySkill9) {
                        buffSkill.setVisible(false);
                    }
                }
            }
        }
        if (hit.isVisible()) {
            hit.setTransform(Sprite.TRANS_NONE);
            if (isCheckHit2) {
                if (iSkill == 1) {
                    if (this.getWidth() >= 200) {
                        if (hit.getY() + hit.getHeight() / 2 > myArena.getY()) {
                            hit.move(0, -20);
                        }
                    } else {
                        if (totalMemory > 1000000) {
                            if (hit.getY() + hit.getHeight() / 2 > myArena.getY()) {
                                hit.move(0, -20);
                            }
                        } else {
                            if (hit.getY() + hit.getHeight() / 2 > 100) {
                                hit.move(0, -20);
                            }
                        }
                    }
                    if (!isHitSkill2) {
                        if (this.getWidth() >= 200) {
                            if (hit.getY() + hit.getHeight() / 2 <= myArena.getY()) {
                                curYFight = 0;
                                hit.setPosition(petDoiThu.getX() - petDoiThu.pet.getWidth() / 2 - 15, 0 - hit.getHeight() - 5);
                                isHitSkill2 = true;
                                timeHitSkill2 = 0;
                            }
                        } else {
                            if (totalMemory > 1000000) {
                                if (hit.getY() + hit.getHeight() / 2 < myArena.getY()) {
                                    curYFight = 0;
                                    hit.setPosition(petDoiThu.getX() - petDoiThu.pet.getWidth() / 2 - 15, 0 - hit.getHeight() - 5);
                                    isHitSkill2 = true;
                                    timeHitSkill2 = 0;
                                }
                            } else {
                                if (hit.getY() + hit.getHeight() / 2 < 100) {
                                    curYFight = 0;
                                    hit.setPosition(petDoiThu.getX() - petDoiThu.pet.getWidth() / 2 - 15, 0 - hit.getHeight() - 5);
                                    isHitSkill2 = true;
                                    timeHitSkill2 = 0;
                                }
                            }
                        }
                    }
                    if (timeHitSkill2 >= 500) {
                        if (hit.getY() < petDoiThu.getY() /*+ petDoiThu.pet.getHeight() - hit.getHeight()*/) {
                            hit.setFrame(1);
                            hit.move(5, 20);
                        } else {
                            hit.setPosition(petDoiThu.getX() - petDoiThu.pet.getWidth() / 2, petDoiThu.getY() /*+ petDoiThu.pet.getHeight() - hit.getHeight()*/);
                        }
                    }
                    if (this.getWidth() >= 200) {
                        if (hit.getY() >= petDoiThu.getY() - 20 && hit.getY() + hit.getHeight() / 2 < myArena.getY()) {
                            isCheckHit2 = false;
                            if (!isReSkill8) {
                                if (!isReSkill7) {
                                    petDoiThu.pet.setFrame(6);
                                    hit.setFrame(2);
                                } else {
                                    oneHitPhandon.setVisible(true);
                                    oneHitPhandon.setPosition(pet[iPet].getX() - (oneHitPhandon.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (oneHitPhandon.getHeight() - pet[iPet].pet.getHeight()) / 2);
                                    oneHitPhandon.setFrame(0);
                                    if (dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend > 0) {
                                        pet[iPet].hp -= dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend;
                                    }
                                    myPet0Hp();
//                                checkHit();
                                }
                            } else {
                                doithuBuffSkill.setVisible(false);
                                checkHit();
                            }
                            if (this.getWidth() > 160) {
                                myWind.setVisible(false);
                                doithuWind.setVisible(false);
                                addNenFight.setVisible(false);
                            }
                            pet[iPet].pet.setFrame(0);
                            if (isReSkill10) {
                                doithuBuffSkill.setVisible(false);
                            }
                            if (isMySkill9) {
                                buffSkill.setVisible(false);
                            }
                        }
                    } else {
                        if (totalMemory > 1000000) {
                            if (hit.getY() >= petDoiThu.getY() - 20 && hit.getY() + hit.getHeight() / 2 < myArena.getY()) {
                                isCheckHit2 = false;
                                if (!isReSkill8) {
                                    if (!isReSkill7) {
                                        petDoiThu.pet.setFrame(6);
                                        hit.setFrame(2);
                                    } else {
                                        oneHitPhandon.setVisible(true);
                                        oneHitPhandon.setPosition(pet[iPet].getX() - (oneHitPhandon.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (oneHitPhandon.getHeight() - pet[iPet].pet.getHeight()) / 2);
                                        oneHitPhandon.setFrame(0);
                                        if (dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend > 0) {
                                            pet[iPet].hp -= dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend;
                                        }
                                        myPet0Hp();
//                                checkHit();
                                    }
                                } else {
                                    doithuBuffSkill.setVisible(false);
                                    checkHit();
                                }
                                if (this.getWidth() > 160) {
                                    myWind.setVisible(false);
                                    doithuWind.setVisible(false);
                                    addNenFight.setVisible(false);
                                }
                                pet[iPet].pet.setFrame(0);
                                if (isReSkill10) {
                                    doithuBuffSkill.setVisible(false);
                                }
                                if (isMySkill9) {
                                    buffSkill.setVisible(false);
                                }
                            }
                        } else {
                            if (hit.getY() >= petDoiThu.getY() - 20 && hit.getY() + hit.getHeight() / 2 < 100) {
                                isCheckHit2 = false;
                                if (!isReSkill8) {
                                    if (!isReSkill7) {
                                        petDoiThu.pet.setFrame(6);
                                        hit.setFrame(2);
                                    } else {
                                        oneHitPhandon.setVisible(true);
                                        oneHitPhandon.setPosition(pet[iPet].getX() - (oneHitPhandon.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (oneHitPhandon.getHeight() - pet[iPet].pet.getHeight()) / 2);
                                        oneHitPhandon.setFrame(0);
                                        if (dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend > 0) {
                                            pet[iPet].hp -= dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend;
                                        }
                                        myPet0Hp();
//                                checkHit();
                                    }
                                } else {
                                    doithuBuffSkill.setVisible(false);
                                    checkHit();
                                }
                                if (this.getWidth() > 160) {
                                    myWind.setVisible(false);
                                    doithuWind.setVisible(false);
                                    addNenFight.setVisible(false);
                                }
                                pet[iPet].pet.setFrame(0);
                                if (isReSkill10) {
                                    doithuBuffSkill.setVisible(false);
                                }
                                if (isMySkill9) {
                                    buffSkill.setVisible(false);
                                }
                            }
                        }
                    }
                }
            }
            if (iSkill == 0 || iSkill == 2 || iSkill == 3 || iSkill == 4) {
                hit.nextFrame();
                hit.move(40, 0);
                if (hit.getX() >= this.getWidth()) {
                    curYFight = 0;
                    if (this.getWidth() >= 200) {
                        if (iSkill != 4) {
                            hit.setPosition(0, doithuArena.getY() + doithuArena.getHeight() / 2 - hit.getHeight() / 2);
                        } else {
                            hit.setPosition(0, doithuArena.getY() + doithuArena.getHeight() / 2 - hit.getHeight() / 2);
                        }
                    } else {
                        if (totalMemory > 1000000) {
                            if (iSkill != 4) {
                                hit.setPosition(0, doithuArena.getY() + doithuArena.getHeight() / 2 - hit.getHeight() / 2);
                            } else {
                                hit.setPosition(0, doithuArena.getY() + doithuArena.getHeight() / 2 - hit.getHeight() / 2);
                            }
                        } else {
                            if (iSkill != 4) {
                                hit.setPosition(0, 0 + 50 - hit.getHeight() / 2);
                            } else {
                                hit.setPosition(0, 0 + 50 - hit.getHeight() / 2);
                            }
                        }
                    }
                }
                if (hit.collidesWith(petDoiThu.pet, true)) {
                    hit.setVisible(false);
                    if (!isReSkill8) {
                        if (!isReSkill7) {
                            oneHit.setVisible(true);
                        } else {
                            oneHit.setVisible(false);
                            doithuBuffSkill.setVisible(false);
                            if (dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend > 0) {
                                pet[iPet].hp -= dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - pet[iPet].defend;
                            }
                            myPet0Hp();
                            oneHitPhandon.setVisible(true);
                            oneHitPhandon.setPosition(pet[iPet].getX() - (oneHitPhandon.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (oneHitPhandon.getHeight() - pet[iPet].pet.getHeight()) / 2);
                            oneHitPhandon.setFrame(0);
                        }
                    } else {
                        oneHit.setVisible(false);
                        doithuBuffSkill.setVisible(false);
                        checkHit();
                    }
                    if (this.getWidth() > 160) {
                        myWind.setVisible(false);
                        doithuWind.setVisible(false);
                        addNenFight.setVisible(false);
                    }
                    pet[iPet].pet.setFrame(0);
                    midlet.display.vibrate(200);
                    if (isReSkill10) {
                        doithuBuffSkill.setVisible(false);
                    }
                    if (isMySkill9) {
                        buffSkill.setVisible(false);
                    }
                }
            }
        }
    }

    public void checkMyPetOneHit() {
        if (oneHit.isVisible()) {
            if (oneHit.getFrame() != oneHit.getFrameSequenceLength() - 1) {
                int x = oneHit.getX();
                int y = oneHit.getY();
                oneHit.setTransform(Sprite.TRANS_NONE);
                oneHit.setPosition(x, y);
                oneHit.nextFrame();
            } else {
                oneHit.setVisible(false);
                oneHit.setFrame(0);
                if (iSkill == 1) {
                    petDoiThu.pet.setFrame(6);
                }
                if (iSkill == 0 || iSkill == 2 || iSkill == 4) {
                    petDoiThu.pet.setFrame(26);
                }
                if (iSkill == 3) {
                    petDoiThu.pet.setFrame(16);
                }
            }
        }
    }

    public void checkDoiThuTrungdon() {
        if (petDoiThu.pet.getFrame() >= 6 && petDoiThu.pet.getFrame() < 16) {
            if (petDoiThu.pet.getFrame() != 15) {
                petDoiThu.pet.nextFrame();
            } else {
                petDoiThu.pet.setFrame(0);
                hit.setVisible(false);
                timeHitSkill2 = 0;
                isHitSkill2 = false;
                checkHit();
            }
        }
        if (petDoiThu.pet.getFrame() >= 16 && petDoiThu.pet.getFrame() < 26) {
            if (petDoiThu.pet.getFrame() != 25) {
                petDoiThu.pet.nextFrame();
            } else {
                petDoiThu.pet.setFrame(0);
                hit.setVisible(false);
                timeHitSkill2 = 0;
                isHitSkill2 = false;
                checkHit();
            }
        }
        if (petDoiThu.pet.getFrame() >= 26 && petDoiThu.pet.getFrame() < 36) {
            if (petDoiThu.pet.getFrame() != 35) {
                petDoiThu.pet.nextFrame();
            } else {
                petDoiThu.pet.setFrame(0);
                hit.setVisible(false);
                timeHitSkill2 = 0;
                isHitSkill2 = false;
                checkHit();
            }
        }
        if (petDoiThu.pet.getFrame() >= 36 && petDoiThu.pet.getFrame() < 46) {
            if (petDoiThu.pet.getFrame() != 45) {
                petDoiThu.pet.nextFrame();
            } else {
                if (iArena != 2) {
                    petDoiThu.pet.setFrame(0);
                } else {
                    petDoiThu.pet.setFrame(petDoiThu.pet.getFrameSequenceLength() - 1);
                    checkPetDoiThuHp();
                    reHitting = false;
                    isYourTurn = true;
                    listSkill.setVisible(true);
                    addSkill.setVisible(true);
                    isHitting = false;
                }
                hit.setVisible(false);
                timeHitSkill2 = 0;
                isHitSkill2 = false;
                if (iArena != 2) {
                    checkHit();
                }
            }
        }
    }

    public void checkDoiThuCreatHit() {
        if (timeWaitReHit >= 3000) {
            if (!isSetVisibleCreat) {
                if (iArena == 0) {
                    petDoiThu.mp -= mana[iRe];
                }
                if (iArena == 1) {
                    if (iRe == 5) {
                        petDoiThu.mp -= 2 * mana[iRe];
                    }
                    if (iRe >= 6) {
                        petDoiThu.mp -= mana[iRe];
                    }
                    if (iRe < 5) {
                        petDoiThu.mp -= 2 * mana[iRe] / 3;
                    }
                }
                if (iArena == 2) {
                    if (iRe == 5) {
                        petDoiThu.mp -= mana[iRe] / 2;
                    } else {
                        if (iRe >= 6) {
                            petDoiThu.mp -= mana[iRe];
                        }
                        if (iRe < 5) {
                            petDoiThu.mp -= 2 * mana[iRe];
                        }
                    }
                }
                if (iArena == 3) {
                    if (iRe == 5) {
                        petDoiThu.mp -= 2 * mana[iRe];
                    }
                    if (iRe >= 6) {
                        petDoiThu.mp -= mana[iRe];
                    }
                    if (iRe < 5) {
                        petDoiThu.mp -= mana[iRe] / 2;
                    }
                }
                if (petDoiThu.mp < 0) {
                    petDoiThu.mp = 0;
                }
                petDoiThu.pet.setFrame(0);
                isSetVisibleCreat = true;
                if (this.getWidth() > 160) {
                    addNenFight.setVisible(true);
                    doithuWind.setVisible(true);
                    myWind.setVisible(true);
                }
                listSkill.setVisible(false);
            }
            if (isAttack) {
                if (petDoiThu.pet.getFrame() < 6) {
                    if (petDoiThu.pet.getFrame() != 5) {
                        petDoiThu.pet.nextFrame();
                        if (iRe == 3) {
                            if (petDoiThu.pet.getFrame() == 2 || petDoiThu.pet.getFrame() == 3) {
                                petDoiThu.pet.setPosition(petDoiThu.getX(), this.getHeight() / 4 - petDoiThu.pet.getHeight() / 2 - 15);
                            } else {
                                petDoiThu.pet.setPosition(petDoiThu.getX(), this.getHeight() / 4 - petDoiThu.pet.getHeight() / 2);
                            }
                        }
                    } else {
                        isAttack = false;
                        if (iRe != 5) {
                            hit.setVisible(true);
                        }
                        if (iRe == 5) {
                            isWaitReHit6 = true;
                        }
                        if (iRe == 4 || iRe == 5) {
                            isShockScreen = true;
                            midlet.display.vibrate(500);
                        }
                    }
                }
            }
        }
    }

    public void checkDoiThuHit() {
        if (iRe == 5) {
            if (timeReHit6 >= 1000) {
                if (!isMySkill8) {
                    if (!isMySkill7) {
                        hit.setVisible(true);
                        pet[iPet].pet.setFrame(36);
                        petDoiThu.pet.setFrame(0);
                    } else {
                        if (this.getWidth() > 160) {
                            myWind.setVisible(false);
                            doithuWind.setVisible(false);
                            addNenFight.setVisible(false);
                        }
                        timeReHit6 = 0;
                        isWaitReHit6 = false;
                        buffSkill.setVisible(false);
                        if (dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - petDoiThu.defend > 0) {
                            petDoiThu.hp -= dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - petDoiThu.defend;
                        }
                        if (petDoiThu.hp <= 0) {
                            petDoiThu.hp = 0;
                            face.setFrameSequence(gameDesign.faceseq003);
                            if (this.getWidth() < 200) {
                                if (iChooseFight == 4) {
                                    isPresentKey = true;
                                }
                                if (numberArena <= 3) {
                                    numberArena++;
                                    key.nextFrame();
                                }
                            } else {
                                if (petDoiThu.level >= 10) {
                                    if (numberArena < 2) {
                                        isPresentKey = true;
                                        numberArena = 2;
                                        key.setFrame(1);
                                    }
                                }
                                if (petDoiThu.level >= 20) {
                                    if (numberArena < 3) {
                                        isPresentKey = true;
                                        numberArena = 3;
                                        key.setFrame(2);
                                    }
                                }
                                if (petDoiThu.level >= 30) {
                                    if (numberArena < 4) {
                                        isPresentKey = true;
                                        numberArena = 4;
                                        key.setFrame(3);
                                    }
                                }
                            }
                            if (this.getWidth() < 200) {
                                money += infoDoithu[iChooseFight][6];
                                pet[iPet].skillPoint += infoDoithu[iChooseFight][3];
                            } else {
                                money += petDoiThu.cost;
                                pet[iPet].skillPoint += petDoiThu.skillPoint;
                            }
                            iAddMainScreen = 7;
                            isWin = true;
                            hit.setVisible(false);
                            isSetVisibleCreat = false;
                            listSkill.setVisible(false);
                            addSkill.setVisible(false);
                            oneHit.setVisible(false);
                            isDoiThuLose[iChooseFight] = true;
                            petDoiThu.pet.setFrame(0);
                            return;
                        }
                        oneHitPhandon.setVisible(true);
                        oneHitPhandon.setPosition(petDoiThu.getX() - (oneHitPhandon.getWidth() - petDoiThu.pet.getWidth()) / 2, petDoiThu.getY() - (oneHitPhandon.getHeight() - petDoiThu.pet.getHeight()) / 2);
                        oneHitPhandon.setFrame(0);
                    }
                } else {
                    if (this.getWidth() > 160) {
                        myWind.setVisible(false);
                        doithuWind.setVisible(false);
                        addNenFight.setVisible(false);
                    }
                    timeReHit6 = 0;
                    isWaitReHit6 = false;
                    buffSkill.setVisible(false);
                    if (isMySkill10) {
                        buffSkill.setVisible(false);
                    }
                    if (isReSkill9) {
                        doithuBuffSkill.setVisible(false);
                        isReSkill9 = false;
                    }
                    checkHit();
                }
            }
            if (hit.isVisible()) {
                if (this.getWidth() >= 200) {
                    curYFight = 2 * myArena.getHeight() - this.getHeight();
                } else {
                    if (totalMemory > 1000000) {
                        curYFight = 2 * myArena.getHeight() - this.getHeight();
                    } else {
                        curYFight = 200 - this.getHeight();
                    }
                }
                if (hit.getFrame() != hit.getFrameSequenceLength() - 1) {
                    hit.nextFrame();
                } else {
                    timeReHit6 = 0;
                    isWaitReHit6 = false;
                    hit.setFrame(hit.getFrameSequenceLength() - 1);
                    if (this.getWidth() > 160) {
                        myWind.setVisible(false);
                        doithuWind.setVisible(false);
                        addNenFight.setVisible(false);
                    }
                }
            }
        }
        if (hit.isVisible()) {
            if (iRe != 5) {
                hit.setTransform(Sprite.TRANS_MIRROR);
            }
            if (iRe == 0 || iRe == 1 || iRe == 2 || iRe == 3 || iRe == 4) {
                hit.nextFrame();
                hit.move(-40, 0);
                if (hit.getX() <= -hit.getHeight()) {
                    if (this.getWidth() >= 200) {
                        curYFight = 2 * myArena.getHeight() - this.getHeight();
                        hit.setPosition(this.getWidth(), myArena.getY() + myArena.getHeight() / 2 - hit.getHeight() / 2);
                    } else {
                        if (totalMemory > 1000000) {
                            curYFight = 2 * myArena.getHeight() - this.getHeight();
                            hit.setPosition(this.getWidth(), myArena.getY() + myArena.getHeight() / 2 - hit.getHeight() / 2);
                        } else {
                            curYFight = 200 - this.getHeight();
                            hit.setPosition(this.getWidth(), 100 + 50 - hit.getHeight() / 2);
                        }
                    }
                }
                if (hit.collidesWith(pet[iPet].pet, true)) {
                    hit.setVisible(false);
                    if (!isMySkill8) {
                        if (!isMySkill7) {
                            oneHit.setVisible(true);
                        } else {
                            oneHit.setVisible(false);
                            buffSkill.setVisible(false);
                            if (dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - petDoiThu.defend > 0) {
                                petDoiThu.hp -= dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - petDoiThu.defend;
                            }
                            if (petDoiThu.hp <= 0) {
                                petDoiThu.hp = 0;
                                face.setFrameSequence(gameDesign.faceseq003);
                                if (this.getWidth() < 200) {
                                    if (iChooseFight == 4) {
                                        isPresentKey = true;
                                    }
                                    if (numberArena <= 3) {
                                        numberArena++;
                                        key.nextFrame();
                                    }
                                } else {
                                    if (petDoiThu.level >= 10) {
                                        if (numberArena < 2) {
                                            isPresentKey = true;
                                            numberArena = 2;
                                            key.setFrame(1);
                                        }
                                    }
                                    if (petDoiThu.level >= 20) {
                                        if (numberArena < 3) {
                                            isPresentKey = true;
                                            numberArena = 3;
                                            key.setFrame(2);
                                        }
                                    }
                                    if (petDoiThu.level >= 30) {
                                        if (numberArena < 4) {
                                            isPresentKey = true;
                                            numberArena = 4;
                                            key.setFrame(3);
                                        }
                                    }
                                }
                                if (this.getWidth() < 200) {
                                    money += infoDoithu[iChooseFight][6];
                                    pet[iPet].skillPoint += infoDoithu[iChooseFight][3];
                                } else {
                                    money += petDoiThu.cost;
                                    pet[iPet].skillPoint += petDoiThu.skillPoint;
                                }
                                iAddMainScreen = 7;
                                isWin = true;
                                hit.setVisible(false);
                                isSetVisibleCreat = false;
                                listSkill.setVisible(false);
                                addSkill.setVisible(false);
                                oneHit.setVisible(false);
                                isDoiThuLose[iChooseFight] = true;
                                petDoiThu.pet.setFrame(0);
                                return;
                            }
                            oneHitPhandon.setVisible(true);
                            oneHitPhandon.setPosition(petDoiThu.getX() - (oneHitPhandon.getWidth() - petDoiThu.pet.getWidth()) / 2, petDoiThu.getY() - (oneHitPhandon.getHeight() - petDoiThu.pet.getHeight()) / 2);
                            oneHitPhandon.setFrame(0);
                        }
                    } else {
                        oneHit.setVisible(false);
                        buffSkill.setVisible(false);
                        checkHit();
                    }
                    if (isMySkill10) {
                        buffSkill.setVisible(false);
                    }
                    if (isReSkill9) {
                        doithuBuffSkill.setVisible(false);
                        isReSkill9 = false;
                    }
                    if (this.getWidth() > 160) {
                        myWind.setVisible(false);
                        doithuWind.setVisible(false);
                        addNenFight.setVisible(false);
                    }
                    petDoiThu.pet.setFrame(0);
                    midlet.display.vibrate(200);
                }
            }
        }
    }

    public void checkDoiThuOneHit() {
        if (oneHit.isVisible()) {
            if (oneHit.getFrame() != oneHit.getFrameSequenceLength() - 1) {
                int x = oneHit.getX();
                int y = oneHit.getY();
                oneHit.setTransform(Sprite.TRANS_MIRROR);
                oneHit.setPosition(x, y);
                oneHit.nextFrame();
            } else {
                oneHit.setVisible(false);
                oneHit.setFrame(0);
                if (iRe == 0 || iRe == 1 || iRe == 2 || iRe == 4) {
                    pet[iPet].pet.setFrame(26);
                }
                if (iRe == 3) {
                    pet[iPet].pet.setFrame(16);
                }
            }
        }
    }

    public void checkMyPetTrungdon() {
        doithuBuffSkill.setVisible(false);
        if (pet[iPet].pet.getFrame() >= 6 && pet[iPet].pet.getFrame() < 16) {
            if (pet[iPet].pet.getFrame() != 15) {
                pet[iPet].pet.nextFrame();
            } else {
                pet[iPet].pet.setFrame(0);
                checkHit();
            }
        }
        if (pet[iPet].pet.getFrame() >= 16 && pet[iPet].pet.getFrame() < 26) {
            if (pet[iPet].pet.getFrame() != 25) {
                pet[iPet].pet.nextFrame();
            } else {
                pet[iPet].pet.setFrame(0);
                checkHit();
            }
        }
        if (pet[iPet].pet.getFrame() >= 26 && pet[iPet].pet.getFrame() < 36) {
            if (pet[iPet].pet.getFrame() != 35) {
                pet[iPet].pet.nextFrame();
            } else {
                pet[iPet].pet.setFrame(0);
                checkHit();
            }
        }
        if (pet[iPet].pet.getFrame() >= 36 && pet[iPet].pet.getFrame() < 46) {
            if (pet[iPet].pet.getFrame() != 45) {
                pet[iPet].pet.nextFrame();
            } else {
                if (iArena != 2) {
                    pet[iPet].pet.setFrame(0);
                } else {
                    checkMyPetHp();
                    pet[iPet].pet.setFrame(pet[iPet].pet.getFrameSequenceLength() - 1);
                    timeWaitReHit = 0;
                    reHitting = true;
                    isYourTurn = false;
                    isHitting = false;
                    isSetVisibleCreat = false;
                    isAttack = true;
                    hit.setPosition(petDoiThu.getX() + hit.getWidth(), petDoiThu.getY() - (hit.getHeight() / 2 - petDoiThu.pet.getHeight() / 2));
                    hit.setVisible(false);
                    randomReSkillFight();
                    oneHit.setPosition(pet[iPet].getX() - oneHit.getWidth() / 2 + pet[iPet].pet.getWidth() / 2, pet[iPet].getY() - (oneHit.getHeight() / 2 - pet[iPet].pet.getHeight() / 2));
                }
                hit.setVisible(false);
                if (iArena != 2) {
                    checkHit();
                }
            }
        }
    }

    public void checkPetDoiThuHp() {
        if (!isReSkill7 && !isReSkill8) {
            if (!isMySkill9) {
                if (iArena == 3 && iSkill <= 4) {
                    if (!isReSkill10) {
                        if (2 * dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - petDoiThu.defend > 0) {
                            petDoiThu.hp -= 2 * dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - petDoiThu.defend;
                        }
                    } else {
                        if (2 * dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - 2 * petDoiThu.defend > 0) {
                            petDoiThu.hp -= 2 * dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - 2 * petDoiThu.defend;
                        }
                        isReSkill10 = false;
                    }
                } else {
                    if (!isReSkill10) {
                        if (dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - petDoiThu.defend > 0) {
                            petDoiThu.hp -= dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - petDoiThu.defend;
                        }
                    } else {
                        if (dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - 2 * petDoiThu.defend > 0) {
                            petDoiThu.hp -= dam[iSkill] * pet[iPet].attack / (100 / acc[iSkill]) - 2 * petDoiThu.defend;
                        }
                        isReSkill10 = false;
                    }
                }
            } else {
                if (iArena == 3 && iSkill < 5) {
                    if (!isReSkill10) {
                        if ((dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - petDoiThu.defend > 0) {
                            petDoiThu.hp -= (dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - petDoiThu.defend;
                        }
                    } else {
                        if ((dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - 2 * petDoiThu.defend > 0) {
                            petDoiThu.hp -= (dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - 2 * petDoiThu.defend;
                        }
                        isReSkill10 = false;
                    }
                } else {
                    if (!isReSkill10) {
                        if ((dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - petDoiThu.defend > 0) {
                            petDoiThu.hp -= (dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - petDoiThu.defend;
                        }
                    } else {
                        if ((dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - 2 * petDoiThu.defend > 0) {
                            petDoiThu.hp -= (dam[iSkill] * 3 * pet[iPet].attack / (100 / acc[iSkill])) / 2 - 2 * petDoiThu.defend;
                        }
                        isReSkill10 = false;
                    }
                }
                isMySkill9 = false;
            }
        } else {
            isReSkill7 = isReSkill8 = false;
        }
        if (petDoiThu.hp <= 0) {
            petDoiThu.hp = 0;
            face.setFrameSequence(gameDesign.faceseq003);
            if (this.getWidth() < 200) {
                if (iChooseFight == 4) {
                    isPresentKey = true;
                }
                if (numberArena <= 3) {
                    numberArena++;
                    key.nextFrame();
                }
            } else {
                if (petDoiThu.level >= 10) {
                    if (numberArena < 2) {
                        isPresentKey = true;
                        numberArena = 2;
                        key.setFrame(1);
                    }
                }
                if (petDoiThu.level >= 20) {
                    if (numberArena < 3) {
                        isPresentKey = true;
                        numberArena = 3;
                        key.setFrame(2);
                    }
                }
                if (petDoiThu.level >= 30) {
                    if (numberArena < 4) {
                        isPresentKey = true;
                        numberArena = 4;
                        key.setFrame(3);
                    }
                }
            }
            if (this.getWidth() < 200) {
                money += infoDoithu[iChooseFight][6];
                pet[iPet].skillPoint += infoDoithu[iChooseFight][3];
            } else {
                money += petDoiThu.cost;
                pet[iPet].skillPoint += petDoiThu.skillPoint;
            }
            iAddMainScreen = 7;
            isWin = true;
            hit.setVisible(false);
            isSetVisibleCreat = false;
            listSkill.setVisible(false);
            addSkill.setVisible(false);
            oneHit.setVisible(false);
            if (this.getWidth() >= 200) {
                isDoiThuLose[iChooseFight] = true;
            }
            return;
        }
    }

    public void checkMyPetHp() {
        if (!isMySkill8 && !isMySkill7) {
            if (!isMySkill10) {
                if (iArena == 3 && iSkill < 5) {
                    if (!isReSkill9) {
                        if (2 * dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - pet[iPet].defend > 0) {
                            pet[iPet].hp -= dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - pet[iPet].defend;
                        }
                    } else {
                        if ((dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - pet[iPet].defend > 0) {
                            pet[iPet].hp -= (dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - pet[iPet].defend;
                        }
                        isReSkill9 = true;
                    }
                } else {
                    if (!isReSkill9) {
                        if (dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - pet[iPet].defend > 0) {
                            pet[iPet].hp -= dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - pet[iPet].defend;
                        }
                    } else {
                        if ((dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - pet[iPet].defend > 0) {
                            pet[iPet].hp -= (dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - pet[iPet].defend;
                        }
                        isReSkill9 = true;
                    }
                }
            } else {
                if (iArena == 3 && iSkill < 5) {
                    if (!isReSkill9) {
                        if (2 * dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - (2 + skilllv[9] - 1) * pet[iPet].defend > 0) {
                            pet[iPet].hp -= dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - (2 + skilllv[9] - 1) * pet[iPet].defend;
                        }
                    } else {
                        if ((dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - (2 + skilllv[9] - 1) * pet[iPet].defend > 0) {
                            pet[iPet].hp -= (dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - (2 + skilllv[9] - 1) * pet[iPet].defend;
                        }
                        isReSkill9 = true;
                    }
                } else {
                    if (!isReSkill9) {
                        if (dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - (2 + skilllv[9] - 1) * pet[iPet].defend > 0) {
                            pet[iPet].hp -= dam[iRe] * petDoiThu.attack / (100 / doithuAcc[iRe]) - (2 + skilllv[9] - 1) * pet[iPet].defend;
                        }
                    } else {
                        if ((dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - (2 + skilllv[9] - 1) * pet[iPet].defend > 0) {
                            pet[iPet].hp -= (dam[iRe] * 3 * petDoiThu.attack / (100 / doithuAcc[iRe])) / 2 - (2 + skilllv[9] - 1) * pet[iPet].defend;
                        }
                        isReSkill9 = true;
                    }
                }
                isMySkill10 = false;
            }
        } else {
            if (isMySkill8) {
                isMySkill8 = false;
            }
            if (isMySkill7) {
                isMySkill7 = false;
            }
        }
        myPet0Hp();
    }

    public void myPet0Hp() {
        if (pet[iPet].hp <= 0) {
            pet[iPet].hp = 0;
            isLose = true;
            if (this.getWidth() < 200) {
                money -= infoDoithu[iChooseFight][6];
            } else {
                money -= petDoiThu.cost;
            }
            if (money <= 0) {
                money = 0;
            }
            pet[iPet].skillPoint -= 5;
            if (pet[iPet].skillPoint <= 0) {
                pet[iPet].skillPoint = 0;
            }
            face.setFrameSequence(gameDesign.faceseq004);
            iAddMainScreen = 7;
            hit.setVisible(false);
            isSetVisibleCreat = false;
            listSkill.setVisible(false);
            addSkill.setVisible(false);
            oneHit.setVisible(false);
            pet[iPet].pet.setFrame(0);
            return;
        }
    }

    public void checkHit() {
        timeDrawYourTurn = 0;
        if (isYourTurn) {
            checkPetDoiThuHp();
            timeWaitReHit = 0;
            reHitting = true;
            isYourTurn = false;
            isHitting = false;
            listSkill.setVisible(true);
            addSkill.setVisible(true);
            isSetVisibleCreat = false;
            isAttack = true;
            hit.setPosition(petDoiThu.getX() + hit.getWidth(), petDoiThu.getY() - (hit.getHeight() / 2 - petDoiThu.pet.getHeight() / 2));
            hit.setVisible(false);
            randomReSkillFight();
            oneHit.setPosition(pet[iPet].getX() - oneHit.getWidth() / 2 + pet[iPet].pet.getWidth() / 2, pet[iPet].getY() - (oneHit.getHeight() / 2 - pet[iPet].pet.getHeight() / 2));
        } else {
            if (petDoiThu.mp < 0) {
                petDoiThu.mp = 0;
            }
            checkMyPetHp();
            reHitting = false;
            isYourTurn = true;
            listSkill.setVisible(true);
            addSkill.setVisible(true);
        }
    }

    public void petAct() {
        if (pet[iPet].getState() == Pet.STATE_EGG || pet[iPet].getState() == Pet.STATE_EGG_NUT) {
            if (pet[iPet].timeAction > 5000 && pet[iPet].timeAction <= 8000) {
                if (!pet[iPet].checkTired()) {
                    pet[iPet].eggJump();
                }
            } else {
                if (!isThiDau) {
                    pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
                }
            }
            if (pet[iPet].isDance) {
                pet[iPet].dance();
            }
        }
        if (pet[iPet].getState() >= Pet.STATE_CHICK_SMALL) {
            if (!isTrain && !isFinishChamsoc) {
                if (pet[iPet].timeAction > 5000 && pet[iPet].timeAction <= 8000 && !isCaress) {
                    if (pet[iPet].checkTired()) {
                        pet[iPet].chickBabyCry();
                    } else {
                        pet[iPet].chickBabySmile();
                    }
                } else {
                    if (!pet[iPet].isMove) {
                        if (pet[iPet].checkTired()) {
                            pet[iPet].pet.setFrame(6);
                        } else {
                            pet[iPet].pet.setFrame(18);
                        }
                    } else {
                        chickMove();
                    }
                }
            }
            if (pet[iPet].isDance || isFinishChamsoc) {
                pet[iPet].chickBabyLove();
            }
            if (isTrainMissed && !isFinishChamsoc) {
                pet[iPet].chickBabySad();
            }
        }
//        if (pet[iPet].getState() == Pet.STATE_PHOENIX) {
//            pet[iPet].phonenixFly();
//        }
    }

    public void chickMove() {
        pet[iPet].chickMove();
        if (pet[iPet].isMoveLeft) {
            if (pet[iPet].getX() >= this.getWidth() / 2 - pet[iPet].pet.getWidth()) {
                int x = pet[iPet].getX();
                int y = 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight();
                pet[iPet].pet.setTransform(Sprite.TRANS_NONE);
                pet[iPet].pet.setPosition(x, y);
                pet[iPet].pet.move(-3, 0);
            } else {
                pet[iPet].isMoveLeft = false;
                pet[iPet].noMove++;
            }
        } else {
            if (pet[iPet].getX() <= this.getWidth() / 2 + pet[iPet].pet.getWidth() / 2) {
                int x = pet[iPet].getX();
                int y = 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight();
                pet[iPet].pet.setTransform(Sprite.TRANS_MIRROR);
                pet[iPet].pet.setPosition(x, y);
                pet[iPet].pet.move(3, 0);
            } else {
                pet[iPet].isMoveLeft = true;
                pet[iPet].noMove++;
            }
        }
        if (pet[iPet].isMoveLeft) {
            if (pet[iPet].noMove >= 10 || pet[iPet].checkTired()) {
                if (pet[iPet].getX() <= this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2) {
                    pet[iPet].isMove = false;
                    pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
                }
            }
        }
    }

    public void setLevelPet() {
        try {
            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                if (pet[iPet].exp >= 60 && isDrawAnouce == false && !isKeyBonus) {
                    isPresentItem = true;
                    isKeyBonus = true;
                }
            }
            if (pet[iPet].exp >= nextLevel[iPet]) {
                pet[iPet].level += 1;
                checkExpNextLevel(iPet);
                if (pet[iPet].level >= 2) {
                    pet[iPet].helthPoint = 0;
                    pet[iPet].foodPoint = 0;
                    pet[iPet].learnPoint = 0;
                    pet[iPet].relaxPoint = 0;
                }
                pet[iPet].cleanPoint = 0;
                pet[iPet].foodPoint = 0;
                pet[iPet].mp += 10;
                pet[iPet].hp += 10;
                pet[iPet].attack += 1;
                pet[iPet].defend += 1;
                pet[iPet].cost += 50;
                isDrawAnouce = true;
                timeDrawAnouce = 0;
                if (pet[iPet].getState() == Pet.STATE_EGG) {
                    pet[iPet].setState(Pet.STATE_EGG_NUT, pet[iPet].chickEggNutseq);
                    return;
                }
                if (pet[iPet].getState() == Pet.STATE_EGG_NUT) {
                    bongEgg.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 14);
                    if (totalMemory < 1000000 && this.getWidth() < 160) {
                        gameDesign.trungga128 = null;
                    }
                    if (this.getWidth() >= 200) {
                        pet[iPet].setImage(gameDesign.getGaCon(), 40, 40);
                    } else {
                        pet[iPet].setImage(gameDesign.getGaCon128(), 25, 25);
                    }
                    pet[iPet].setState(Pet.STATE_CHICK_SMALL, pet[iPet].chickBabyseq);
                    return;
                }
                if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL && pet[iPet].level == LV_MEDIUM) {
                    bongEgg.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight() + 14);
                    if (totalMemory < 1000000 && this.getWidth() < 160) {
                        gameDesign.trungga128 = null;
                    }
                    if (this.getWidth() >= 200) {
                        pet[iPet].setImage(gameDesign.getGaTrungBinh(), 60, 60);
                    } else {
                        pet[iPet].setImage(gameDesign.getGaTrungBinh128(), 40, 40);
                    }
                    pet[iPet].setState(Pet.STATE_CHICK_MEDIUM, pet[iPet].chickMediumseq);
                    return;
                }
                if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM && pet[iPet].level == LV_BIG) {
                    if (totalMemory < 1000000 && this.getWidth() < 160) {
                        gameDesign.gaCon128 = null;
                    }
                    if (pet[iPet].level >= LV_BIG) {
                        if (this.getWidth() >= 200) {
                            pet[iPet].setImage(gameDesign.getGaLon(), 70, 70);
                            pet[iPet].setState(Pet.STATE_CHICK_BIG, pet[iPet].chickMediumseq);
                            bongEgg.setPosition(this.getWidth() / 2 - bongEgg.getWidth() / 2, bongEgg.getY());
//                        pet[iPet].setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, bongEgg.getY() - pet[iPet].pet.getHeight());
                        } else {
                            pet[iPet].setImage(gameDesign.getGaLon128(), 45, 45);
                            pet[iPet].setState(Pet.STATE_CHICK_BIG, pet[iPet].chickMediumseq);
                            bongEgg.setPosition(this.getWidth() / 2 - bongEgg.getWidth() / 2, bongEgg.getY());
                        }
                        return;
                    }
                }
                if (pet[iPet].getState() == Pet.STATE_PHOENIX) {
                    pet[iPet].helthPoint = 100;
                    pet[iPet].foodPoint = 100;
                    pet[iPet].learnPoint = 100;
                    pet[iPet].relaxPoint = 100;
                    pet[iPet].cleanPoint = 100;
                }
                for (int i = 0; i < isUseSkill.length; i++) {
                    if (pet[iPet].level >= levelUseSkill[i]) {
                        isUseSkill[i] = true;
                    }
                }
            }
//            needScoreTrain = 10;
            if (pet[iPet].level < 10) {
                needScoreTrain = 50;
            } else if (pet[iPet].level < 20) {
                needScoreTrain = 80;
            } else {
                needScoreTrain = 100;
            }
//            needScoreTrain = (pet[iPet].level + 1) * 50;
//            needScoreTrain = 10;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void checkThinking() {
        if (pet[iPet].cleanPoint <= 0) {
            if (!thinking.isVisible()) {
                isDrPetThk1 = true;
            }
            iconThinking.setFrame(0);
            thinking.setVisible(true);
            thinking.setPosition(pet[iPet].getX() - thinking.getWidth(), pet[iPet].getY() - thinking.getHeight() + 6);
            iconThinking.setVisible(true);
            iconThinking.setPosition(thinking.getX() + thinking.getWidth() / 2 - iconThinking.getWidth() / 2, thinking.getY());
        } else if (pet[iPet].foodPoint <= 0) {
            if (!thinking.isVisible()) {
                isDrPetThk1 = true;
            }
            iconThinking.setFrame(1);
            thinking.setVisible(true);
            thinking.setPosition(pet[iPet].getX() - thinking.getWidth(), pet[iPet].getY() - thinking.getHeight() + 6);
            iconThinking.setVisible(true);
            iconThinking.setPosition(thinking.getX() + thinking.getWidth() / 2 - iconThinking.getWidth() / 2, thinking.getY());
        } else if (pet[iPet].learnPoint <= 0) {
            if (!thinking.isVisible()) {
                isDrPetThk1 = true;
            }
            iconThinking.setFrame(2);
            thinking.setVisible(true);
            thinking.setPosition(pet[iPet].getX() - thinking.getWidth(), pet[iPet].getY() - thinking.getHeight() + 6);
            iconThinking.setVisible(true);
            iconThinking.setPosition(thinking.getX() + thinking.getWidth() / 2 - iconThinking.getWidth() / 2, thinking.getY());
        } else if (pet[iPet].helthPoint <= 0) {
            if (!thinking.isVisible()) {
                isDrPetThk1 = true;
            }
            iconThinking.setFrame(4);
            thinking.setVisible(true);
            thinking.setPosition(pet[iPet].getX() - thinking.getWidth(), pet[iPet].getY() - thinking.getHeight() + 6);
            iconThinking.setVisible(true);
            iconThinking.setPosition(thinking.getX() + thinking.getWidth() / 2 - iconThinking.getWidth() / 2, thinking.getY());
        } else if (pet[iPet].relaxPoint <= 0) {
            if (!thinking.isVisible()) {
                isDrPetThk1 = true;
            }
            iconThinking.setFrame(3);
            thinking.setVisible(true);
            thinking.setPosition(pet[iPet].getX() - thinking.getWidth(), pet[iPet].getY() - thinking.getHeight() + 6);
            iconThinking.setVisible(true);
            iconThinking.setPosition(thinking.getX() + thinking.getWidth() / 2 - iconThinking.getWidth() / 2, thinking.getY());
        }
        if (!pet[iPet].checkTired()) {
            isDrPetThk1 = false;
        }
    }

    public void clean() {
        if (broom.getFrame() < broom.getFrameSequenceLength() - 1) {
            broom.nextFrame();
        } else {
            broom.setFrame(0);
        }
        if (dust.getFrame() < dust.getFrameSequenceLength() - 1) {
            dust.nextFrame();
        } else {
            dust.setFrame(0);
            pet[iPet].noClean++;
        }
        iconThinking.setVisible(false);
        thinking.setVisible(false);
        if (pet[iPet].noClean == 3) {
            broom.setVisible(false);
            dust.setVisible(false);
            isFinishChamsoc = true;
//            isCleaning = false;
            pet[iPet].noClean = 0;
//            pet1.cleanPoint += 50;
            thinking.setVisible(false);
            iconThinking.setVisible(false);
        }
        if (isFinishChamsoc) {
            if (timeWaitChamsoc >= 1500) {
                isFinishChamsoc = false;
                timeWaitChamsoc = 0;
                isCleaning = false;
                pointer.setVisible(true);
            }
        }
    }

    public void doctor() {
        if (timeDoctor <= 100) {
            doctor.setPosition(pet[iPet].pet.getX() + pet[iPet].pet.getWidth() / 2 + 2, pet[iPet].pet.getY() - doctor.getHeight() / 2 - 10);
        } else if (timeDoctor <= 200) {
            doctor.setPosition(pet[iPet].pet.getX() + pet[iPet].pet.getWidth() / 2, pet[iPet].pet.getY() - doctor.getHeight() / 2);
        } else if (timeDoctor <= 300) {
            timeDoctor = 0;
            noDoctor++;
            doctor.setPosition(pet[iPet].pet.getX() + pet[iPet].pet.getWidth() / 2 + 1, pet[iPet].pet.getY() - doctor.getHeight() / 2 - 5);
        }
        iconThinking.setVisible(false);
        thinking.setVisible(false);
        if (noDoctor == 5) {
            noDoctor = 0;
            timeDoctor = 0;
            isFinishChamsoc = true;
            doctor.setVisible(false);
        }
        if (isFinishChamsoc) {
            if (timeWaitChamsoc >= 2000) {
                isFinishChamsoc = false;
                timeWaitChamsoc = 0;
                isDoctor = false;
                pointer.setVisible(true);
            }
        }
    }

    public void learn() {
        if (pencil.getFrame() != pencil.getFrameSequenceLength() - 1) {
            pencil.nextFrame();
        } else {
            pet[iPet].noLearn++;
            pencil.setFrame(0);
        }
        iconThinking.setVisible(false);
        thinking.setVisible(false);
        if (pet[iPet].noLearn == 4) {
            pet[iPet].noLearn = 0;
            isFinishChamsoc = true;
            noteBook.setVisible(false);
            pencil.setVisible(false);
            pencil.setFrame(0);
        }
        if (isFinishChamsoc) {
            if (timeWaitChamsoc >= 2000) {
                isFinishChamsoc = false;
                timeWaitChamsoc = 0;
                isLearning = false;
                pointer.setVisible(true);
            }
        }
    }

    public void eat() {
        face.setPosition(this.getWidth() / 2 - face.getWidth() / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - face.getHeight() / 2);
        if (face.getFrame() < 4) {
            if (face.getFrame() < 3) {
                face.nextFrame();
            } else {
                pet[iPet].noEat++;
                face.setFrame(0);
            }
        }
        if (face.getFrame() >= 4) {
            if (face.getFrame() != 7) {
                face.nextFrame();
            } else {
                pet[iPet].noEat++;
                face.setFrame(4);
            }
        }
        iconThinking.setVisible(false);
        thinking.setVisible(false);
        if (pet[iPet].noEat == 5 && face.getFrame() < 4) {
            face.setFrame(4);
        }
        if (pet[iPet].noEat == 10) {
            if (noFood > 0) {
                noFood -= 1;
            }
            pet[iPet].noEat = 0;
            isFinishChamsoc = true;
            face.setFrame(0);
            face.setVisible(false);
            pet[iPet].pet.setVisible(true);
        }
        if (isFinishChamsoc) {
            if (timeWaitChamsoc >= 2000) {
                isFinishChamsoc = false;
                timeWaitChamsoc = 0;
                isEating = false;
                pointer.setVisible(true);
            }
        }
    }

    public void randomTrainArrow() {
        for (int i = 0; i < iInputArrow.length; i++) {
            iInputArrow[i] = r.nextInt(iInputArrow.length) + iInputArrow.length + 1;
            trainArrow.setCell(i, 0, iInputArrow[i]);
        }
        iArrow = 0;
        isArrowPressed = false;
        isTrainMissed = false;
        xLight = trainArrow.getX();
    }

    public void randomDoithu(int index) {
        infoDoithu[index][0] = r.nextInt(8) + 2 * index;
        infoDoithu[index][1] = r.nextInt(8) + 2 * index + 12;
        infoDoithu[index][2] = r.nextInt(8) + 2 * index + 15;
        infoDoithu[index][3] = r.nextInt(8) + 2 * index + 2;
        infoDoithu[index][4] = r.nextInt(8) + 2 * index + 2;
        infoDoithu[index][5] = r.nextInt(8) + 2 * index + 2;
        doithuBottleHP = 2;
        doithuBottleMP = 2;
    }

    public void setInfoDoiThu(int indexArena) {
        if (this.getWidth() >= 200) {
            try {
                if (indexArena == 0) {
                    choosenFight.setStaticTileSet(gameDesign.getGaCon(), 40, 40);
                }
                if (indexArena == 1) {
                    choosenFight.setStaticTileSet(gameDesign.getGaTrungBinh(), 60, 60);
                }
                if (indexArena >= 2) {
                    choosenFight.setStaticTileSet(gameDesign.getGaLon(), 70, 70);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            try {
//                setNullImageChickFight();
                choosenFight.setStaticTileSet(gameDesign.getGa_con_chien_dau128(), 25, 25);
//                if (indexArena == 0) {
//                    choosenFight.setStaticTileSet(gameDesign.getGaCon128(), 25, 25);
//                }
//                if (indexArena == 1) {
//                    choosenFight.setStaticTileSet(gameDesign.getGaTrungBinh128(), 40, 40);
//                }
//                if (indexArena >= 2) {
//                    choosenFight.setStaticTileSet(gameDesign.getGaLon128(), 45, 45);
//                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        int[][] tiles = {
            {1, 1, 1, 1, 1}
        };
        // write mid-init user code here
        for (int row = 0; row < 1; row++) {
            for (int col = 0; col < 5; col++) {
                choosenFight.setCell(col, row, tiles[row][col]);
            }
        }
        if (indexArena == 0) {
            infoDoithu[0][0] = 2;
            infoDoithu[0][1] = 30;
            infoDoithu[0][2] = 80;
            infoDoithu[0][3] = 5;//điểm sẽ được cộng cho thú nuôi
            infoDoithu[0][4] = 8;
            infoDoithu[0][5] = 10;
            infoDoithu[0][6] = 100;
            //
            infoDoithu[1][0] = 4;
            infoDoithu[1][1] = 60;
            infoDoithu[1][2] = 120;
            infoDoithu[1][3] = 6;
            infoDoithu[1][4] = 12;
            infoDoithu[1][5] = 8;
            infoDoithu[1][6] = 150;
            //
            infoDoithu[2][0] = 6;
            infoDoithu[2][1] = 60;
            infoDoithu[2][2] = 150;
            infoDoithu[2][3] = 8;
            infoDoithu[2][4] = 14;
            infoDoithu[2][5] = 14;
            infoDoithu[2][6] = 200;
            //
            infoDoithu[3][0] = 8;
            infoDoithu[3][1] = 80;
            infoDoithu[3][2] = 150;
            infoDoithu[3][3] = 10;
            infoDoithu[3][4] = 14;
            infoDoithu[3][5] = 16;
            infoDoithu[3][6] = 250;
            //
            infoDoithu[4][0] = 9;
            infoDoithu[4][1] = 150;
            infoDoithu[4][2] = 150;
            infoDoithu[4][3] = 12;
            infoDoithu[4][4] = 10;
            infoDoithu[4][5] = 20;
            infoDoithu[4][6] = 400;
        } else if (indexArena == 1) {
            infoDoithu[0][0] = 10;
            infoDoithu[0][1] = 100;
            infoDoithu[0][2] = 200;
            infoDoithu[0][3] = 14;//điểm sẽ được cộng cho thú nuôi
            infoDoithu[0][4] = 17;
            infoDoithu[0][5] = 10;
            infoDoithu[0][6] = 400;
            //
            infoDoithu[1][0] = 12;
            infoDoithu[1][1] = 160;
            infoDoithu[1][2] = 240;
            infoDoithu[1][3] = 16;
            infoDoithu[1][4] = 15;
            infoDoithu[1][5] = 18;
            infoDoithu[1][6] = 500;
            //
            infoDoithu[2][0] = 14;
            infoDoithu[2][1] = 160;
            infoDoithu[2][2] = 300;
            infoDoithu[2][3] = 18;
            infoDoithu[2][4] = 20;
            infoDoithu[2][5] = 20;
            infoDoithu[2][6] = 600;
            //
            infoDoithu[3][0] = 16;
            infoDoithu[3][1] = 150;
            infoDoithu[3][2] = 350;
            infoDoithu[3][3] = 20;
            infoDoithu[3][4] = 22;
            infoDoithu[3][5] = 20;
            infoDoithu[3][6] = 700;
            //
            infoDoithu[4][0] = 18;
            infoDoithu[4][1] = 200;
            infoDoithu[4][2] = 450;
            infoDoithu[4][3] = 22;
            infoDoithu[4][4] = 30;
            infoDoithu[4][5] = 20;
            infoDoithu[4][6] = 800;
        } else if (indexArena == 2) {
            infoDoithu[0][0] = 20;
            infoDoithu[0][1] = 200;
            infoDoithu[0][2] = 500;
            infoDoithu[0][3] = 24;//điểm sẽ được cộng cho thú nuôi
            infoDoithu[0][4] = 18;
            infoDoithu[0][5] = 20;
            infoDoithu[0][6] = 800;
            //
            infoDoithu[1][0] = 22;
            infoDoithu[1][1] = 210;
            infoDoithu[1][2] = 550;
            infoDoithu[1][3] = 26;
            infoDoithu[1][4] = 20;
            infoDoithu[1][5] = 25;
            infoDoithu[1][6] = 950;
            //
            infoDoithu[2][0] = 24;
            infoDoithu[2][1] = 250;
            infoDoithu[2][2] = 600;
            infoDoithu[2][3] = 28;
            infoDoithu[2][4] = 25;
            infoDoithu[2][5] = 20;
            infoDoithu[2][6] = 1100;
            //
            infoDoithu[3][0] = 26;
            infoDoithu[3][1] = 280;
            infoDoithu[3][2] = 700;
            infoDoithu[3][3] = 30;
            infoDoithu[3][4] = 25;
            infoDoithu[3][5] = 30;
            infoDoithu[3][6] = 1250;
            //
            infoDoithu[4][0] = 28;
            infoDoithu[4][1] = 300;
            infoDoithu[4][2] = 850;
            infoDoithu[4][3] = 30;
            infoDoithu[4][4] = 30;
            infoDoithu[4][5] = 40;
            infoDoithu[4][6] = 1400;
        } else if (indexArena == 3) {
            infoDoithu[0][0] = 30;
            infoDoithu[0][1] = 350;
            infoDoithu[0][2] = 800;
            infoDoithu[0][3] = 32;//điểm sẽ được cộng cho thú nuôi
            infoDoithu[0][4] = 40;
            infoDoithu[0][5] = 40;
            infoDoithu[0][6] = 1500;
            //
            infoDoithu[1][0] = 32;
            infoDoithu[1][1] = 400;
            infoDoithu[1][2] = 900;
            infoDoithu[1][3] = 34;
            infoDoithu[1][4] = 40;
            infoDoithu[1][5] = 50;
            infoDoithu[1][6] = 1700;
            //
            infoDoithu[2][0] = 34;
            infoDoithu[2][1] = 400;
            infoDoithu[2][2] = 850;
            infoDoithu[2][3] = 36;
            infoDoithu[2][4] = 55;
            infoDoithu[2][5] = 20;
            infoDoithu[2][6] = 1900;
            //
            infoDoithu[3][0] = 36;
            infoDoithu[3][1] = 450;
            infoDoithu[3][2] = 1000;
            infoDoithu[3][3] = 38;
            infoDoithu[3][4] = 60;
            infoDoithu[3][5] = 70;
            infoDoithu[3][6] = 2100;
            //
            infoDoithu[4][0] = 38;
            infoDoithu[4][1] = 750;
            infoDoithu[4][2] = 1200;
            infoDoithu[4][3] = 40;
            infoDoithu[4][4] = 100;
            infoDoithu[4][5] = 100;
            infoDoithu[4][6] = 3000;
        }
    }

    public void setAccDoiThu(int iDoiThu) {
        if (iDoiThu <= 1) {
            doithuAcc[0] = 100;
            doithuAcc[1] = 50;
            doithuAcc[2] = 50;
            doithuAcc[3] = 50;
            doithuAcc[4] = 50;
            doithuAcc[5] = 50;
            doithuAcc[6] = doithuAcc[7] = doithuAcc[8] = doithuAcc[9] = 0;
        } else if (iDoiThu <= 3) {
            doithuAcc[0] = 100;
            doithuAcc[1] = 50;
            doithuAcc[2] = 50;
            doithuAcc[3] = 50;
            doithuAcc[4] = 50;
            doithuAcc[5] = 50;
            doithuAcc[6] = doithuAcc[7] = doithuAcc[8] = doithuAcc[9] = 0;
        } else if (iDoiThu <= 4) {
            doithuAcc[0] = 100;
            doithuAcc[1] = 100;
            doithuAcc[2] = 100;
            doithuAcc[3] = 100;
            doithuAcc[4] = 100;
            doithuAcc[5] = 100;
            doithuAcc[6] = doithuAcc[7] = doithuAcc[8] = doithuAcc[9] = 0;
        }
    }

    public void sellPet(int iPet) {
        try {
            lmInfo.remove(pet[iPet].pet);
            lmFight.remove(pet[iPet].pet);
            lm.remove(pet[iPet].pet);
            lmChoosePet.remove(pet[iPet].pet);
            this.money += pet[iPet].cost;
            pet[iPet] = null;
            for (int i = 0; i < skilllv.length; i++) {
                skilllv[i] = 1;
            }
            for (int i = 0; i < noUpMyInfo.length; i++) {
                noUpMyInfo[i] = 0;
            }
            if (iPet == 0) {
                midlet.infoPet1.updateInfo(false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", true, 1, 0, 0, 0, 0, 0, 0, 0, 0, skilllv, noUpMyInfo, false);
            } else {
                midlet.infoPet2.updateInfo(false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", true, 1, 0, 0, 0, 0, 0, 0, 0, 0, skilllv, noUpMyInfo, false);
            }
            nextLevel[iPet] = 30;
            isSellPet = false;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void mainMenuActive(Graphics g) {
        if (!isOpenSubMenu) {
            if (isMainBeginDown) {
                mainMenuDown();
            } else {
                for (int i = 0; i < mainMenu.length; i++) {
                    mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), topMainMenu);
                    if (iMainMenu == i) {
                        if (this.getWidth() >= 200) {
                            if (mainMenu[i].getY() > topMainMenu - 18) {
                                mainMenu[i].move(0, -6);
                            } else {
                                mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), 256);
                            }
                        } else {
                            mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), topMainMenu - 5);
                        }
                    }
                }
                if (!isLock) {
                    if (this.getWidth() >= 200) {
                        g.setFont(font2);
                    } else {
                        g.setFont(font1);
                    }
                    g.drawString(sMainMenu[iMainMenu], this.getWidth() / 2, topMainMenu + mainMenu[iMainMenu].getHeight(), Graphics.TOP | Graphics.HCENTER);
                }
            }
        } else {
//            mainMenuDown();
            if (isMainBeginUp) {
                mainMenuUp();
            }
        }
    }

    public void mainMenuDown() {
        for (int i = 0; i < mainMenu.length; i++) {
            if (mainMenu[0].getY() <= this.getHeight()) {
                if (mainMenu[0].getY() < this.getHeight() + 10) {
                    mainMenu[i].move(0, 10);
                }
            } else {
//                isMainBeginDown = false;
//                isOpenSubMenu = true;
                isSubBeginRight = true;
                mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), this.getHeight());
            }
        }
    }

    public void mainMenuUp() {
        for (int i = 0; i < mainMenu.length; i++) {
            if (mainMenu[0].getY() > topMainMenu) {
                mainMenu[i].move(0, -10);
            } else {
//                isMainMenuUp = false;
                isSubBeginLeft = false;
                isMainBeginUp = false;
                isOpenSubMenu = false;
                mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), topMainMenu);
            }
        }
    }

    public void subMenuActive(Graphics g, Sprite subMenu[], String sSubMenu[], int iSubMenu) {
        if (isOpenSubMenu) {
            if (isSubBeginLeft) {
                subMenuMoveLeft(subMenu);
            } else {
                for (int i = 0; i < subMenu.length; i++) {
//                if (!isSubMenuRight) {
                    subMenu[i].setPosition(mainMenu[0].getX() + i * subMenu[i].getWidth(), topMainMenu);
                    if (iSubMenu == i) {
                        if (this.getWidth() >= 200) {
                            if (subMenu[0].getY() > topMainMenu - 18) {
                                subMenu[i].move(0, -6);
                            } else {
                                subMenu[i].setPosition(mainMenu[0].getX() + i * subMenu[i].getWidth(), topMainMenu - 18);
                            }
                        } else {
                            subMenu[i].setPosition(mainMenu[0].getX() + i * subMenu[i].getWidth(), topMainMenu - 5);
                        }
                    }
                    if (this.getWidth() >= 200) {
                        g.setFont(font2);
                    } else {
                        g.setFont(font1);
                    }
                    g.drawString(sSubMenu[iSubMenu], this.getWidth() / 2, topMainMenu + subMenu[0].getHeight(), Graphics.TOP | Graphics.HCENTER);
                }
            }
        } else {
            if (isSubBeginRight) {
                subMenuMoveRight(subMenu);
            }
        }
    }

    public void subMenuMoveLeft(Sprite subMenu[]) {
        for (int i = 0; i < subMenu.length; i++) {
            if (subMenu[subMenu.length - 1].getX() + subMenu[subMenu.length - 1].getWidth() > 0) {
                subMenu[i].move(-subMenu[i].getWidth() * subMenu.length / 4, 0);
            } else {
//                isSubBeginLeft = false;
                isMainBeginUp = true;
            }
        }
    }

    public void subMenuMoveRight(Sprite subMenu[]) {
//        for (int i = 0; i < subMenu.length; i++) {
//            if (subMenu[0].getX() < mainMenu[0].getX()) {
//                subMenu[i].move(subMenu[i].getWidth() * subMenu.length / 4, 0);
//            } else {
//                isMainBeginDown = false;
//                isSubBeginRight = false;
//                isOpenSubMenu = true;
//                subMenu[i].setPosition(mainMenu[0].getX() + i * subMenu[i].getWidth(), topMainMenu);
//            }
//        }
        if (subMenu[0].getX() < mainMenu[0].getX()) {
            for (int i = 0; i < subMenu.length; i++) {
                subMenu[i].move(subMenu[i].getWidth() * subMenu.length / 4, 0);
            }
        } else {
            for (int i = 0; i < subMenu.length; i++) {
                isMainBeginDown = false;
                isSubBeginRight = false;
                isOpenSubMenu = true;
                subMenu[i].setPosition(mainMenu[0].getX() + i * subMenu[i].getWidth(), topMainMenu);
            }
        }
    }

    private void pointerMove() {
        if (pointer.isVisible()) {
            if (timePoinNhay <= 100) {
                pointer.setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[0].getWidth() / 2 + mainMenu[0].getWidth() / 2 - pointer.getWidth() / 2 + iPointer * mainMenu[0].getWidth(), topMainMenu - 3 - pointer.getHeight());
            } else if (timePoinNhay <= 200) {
                pointer.setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[0].getWidth() / 2 + mainMenu[0].getWidth() / 2 - pointer.getWidth() / 2 + iPointer * mainMenu[0].getWidth(), topMainMenu - 3 - pointer.getHeight() + 3);
            } else if (timePoinNhay <= 300) {
                timePoinNhay = 0;
                pointer.setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[0].getWidth() / 2 + mainMenu[0].getWidth() / 2 - pointer.getWidth() / 2 + iPointer * mainMenu[0].getWidth(), topMainMenu - 3 - pointer.getHeight() - 3);
            }
        }
    }

    protected void keyPressed(int keyCode) {
        int instantkeyCode = KeyCodeAdapter.getInstance().adoptKeyCode(keyCode);
        switch (instantkeyCode) {
            case KeyCodeAdapter.LEFT_KEY:
                if (!isMainBeginDown && !isMainBeginUp && !isSubBeginLeft && !isSubBeginRight && !isChamsoc && !isLoadingWalk && !isHitting && !isSellPet) {
                    leftkey();
                }
                return;
            case KeyCodeAdapter.RIGHT_KEY:
                if (!isMainBeginDown && !isMainBeginUp && !isSubBeginLeft && !isSubBeginRight && !isChamsoc && !isLoadingWalk && !isHitting && !isSellPet) {
                    rightkey();
                }
                return;
            case KeyCodeAdapter.DOWN_KEY:
                if (!isHitting) {
                    downKey();
                }
                return;
            case KeyCodeAdapter.UP_KEY:
                if (!isHitting) {
                    upKey();
                }
                return;
            case KeyCodeAdapter.CENTER_KEY:
                if (!isMainBeginDown && !isMainBeginUp && !isChamsoc && !isPresentItem && !isLoadingWalk) {
                    fireKey();
                }
                return;
            case KeyCodeAdapter.SOFT_KEY_MIDDLE_INTERNET:
                fireKey();
                return;
            case KeyCodeAdapter.SOFT_KEY_LEFT:
                if (!isLoadingWalk) {
                    try {
                        menuLeftKey();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
                return;
            case KeyCodeAdapter.SOFT_KEY_RIGHT:
                if (!isLoadingWalk) {
                    menuRightKey();
                }
                return;
            case KeyCodeAdapter.KEY_2:
                upKey();
                return;
            case KeyCodeAdapter.KEY_8:
                downKey();
                return;
            case KeyCodeAdapter.KEY_4:
                if (!isMainBeginDown && !isMainBeginUp && !isSubBeginLeft && !isSubBeginRight && !isChamsoc && !isLoadingWalk && !isSellPet) {
                    leftkey();
                }
                return;
            case KeyCodeAdapter.KEY_6:
                if (!isMainBeginDown && !isMainBeginUp && !isSubBeginLeft && !isSubBeginRight && !isChamsoc && !isLoadingWalk && !isSellPet) {
                    rightkey();
                }
                return;
            case KeyCodeAdapter.KEY_5:
                if (!isMainBeginDown && !isMainBeginUp && !isSubBeginLeft && !isSubBeginRight && !isChamsoc && !isLoadingWalk) {
                    fireKey();
                }
                return;
            case KeyCodeAdapter.KEY_1:
                if (isBeginFight && !isLose && !isWin) {
                    if (noBottleHP > 0) {
                        noBottleHP--;
                        pet[iPet].hp += 50;
                        if (pet[iPet].hp > maxHPMe) {
                            pet[iPet].hp = maxHPMe;
                        }
                    }
                }
                return;
            case KeyCodeAdapter.KEY_3:
                if (isBeginFight && !isLose && !isWin) {
                    if (noBottleMP > 0) {
                        noBottleMP--;
                        pet[iPet].mp += 50;
                        if (pet[iPet].mp > maxMPMe) {
                            pet[iPet].mp = maxMPMe;
                        }
                    }
                }
                return;
        }
    }

    public void pointerPressedMainMenu(int x, int y) {
        if (y <= topMainMenu + mainMenu[0].getHeight() + 5 && y >= topMainMenu - 5) {
            for (int i = 0; i < mainMenu.length; i++) {
                if (x >= mainMenu[i].getX() && x <= mainMenu[i].getX() + mainMenu[i].getWidth()) {
                    iMainMenu = i;
                }
            }
            iPointer = iMainMenu;
            TimerTask timeTask = new TimerTask() {

                public void run() {
                    mainMenuPressed();
                }
            };
            Timer timer = new Timer();
            timer.schedule(timeTask, 4 * delay);
        }
    }

    public void pointerPressedSubMenu(int x, int y) {
        if (y <= topMainMenu + mainMenu[0].getHeight() + 5 && y >= topMainMenu - 5) {
            if (iMainMenu == 0) {
                for (int i = 0; i < subMenu1.length; i++) {
                    if (x >= subMenu1[i].getX() && x <= subMenu1[i].getWidth() + subMenu1[i].getX()) {
                        iSubMenu1 = i;
                    }
                }
                iPointer = iSubMenu1;
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        subMenuPressed();
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 4 * delay);
            }
            if (iMainMenu == 2) {
                for (int i = 0; i < subMenu3.length; i++) {
                    if (x >= subMenu3[i].getX() && x <= subMenu3[i].getWidth() + subMenu3[i].getX()) {
                        iSubMenu3 = i;
                    }
                }
                iPointer = iSubMenu3;
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        subMenuPressed();
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 4 * delay);
            }
        }
    }

    public void pointerPressedMenuFight(int x, int y) {
        int strW = font2.stringWidth("Chọn đấu trường");
        if (x >= this.getWidth() / 2 - strW / 2 - 10 && x <= this.getWidth() / 2 + strW / 2 + 10) {
            if (y < this.getHeight() / 2 - (4 * font2.getHeight() + 30) / 2) {
                if (iMenuFight > 0) {
                    iMenuFight--;
                } else {
                    iMenuFight = 3;
                }
            } else if (y > this.getHeight() / 2 - (4 * font2.getHeight() + 30) / 2 + 50 + 4 * font2.getHeight() + 10) {
                if (iMenuFight < 3) {
                    iMenuFight++;
                } else {
                    iMenuFight = 0;
                }
            } else {
                iMenuFight = (y - this.getHeight() / 2 + (4 * font2.getHeight() + 30) / 2) / (10 + font2.getHeight());
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        menuFightPressed();
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 4 * delay);
            }
        }
    }

    public void pointerPressedChooSkillFight(int x, int y) {
        if (x > listChooseSkill.getX() - 2 && x < listChooseSkill.getX() + listChooseSkill.getWidth() + 2) {
            if (y >= listChooseSkill.getY() && y <= listChooseSkill.getY() + listChooseSkill.getHeight()) {
                iChooseSkillFight = (y - listChooseSkill.getY()) / listChooseSkill.getCellHeight();
            }
        }
    }

    public void pointerPressedChooseFight(int x, int y) {
        if (y >= choosenFight.getY() && y <= choosenFight.getY() + choosenFight.getHeight()) {
            if (x >= choosenFight.getX() && x <= choosenFight.getX() + choosenFight.getWidth()) {
                iChooseFight = (x - choosenFight.getX()) / choosenFight.getCellWidth();
            }
        } else {
            if (y >= this.getHeight() - 3 * font1.getHeight() / 2) {
                if (x >= this.getWidth() / 2 - font1.stringWidth("OK") / 2 - 3 && x <= this.getWidth() / 2 + font1.stringWidth("OK") / 2 + 3) {
                    TimerTask timeTask = new TimerTask() {

                        public void run() {
                            okChooseFight();
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(timeTask, 4 * delay);
                }
            }
        }
    }

    public void pointerPressedBeginFight(int x, int y) {
        if (y >= listSkill.getY() && y <= listSkill.getY() + listSkill.getHeight()) {
            if (x >= listSkill.getX() && x < listSkill.getX() + listSkill.getWidth()) {
                if (y >= listSkill.getY() && y <= listSkill.getY() + listSkill.getCellHeight()) {
                    iSkill = (x - listSkill.getX()) / listSkill.getCellWidth();
                } else {
                    iSkill = 5 + (x - listSkill.getX()) / listSkill.getCellWidth();
                }
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        okSkillFight();
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 4 * delay);
            }
        }
    }

    public void pointerPressedBomMau(int x, int y) {
        if (y >= bottleHP.getY() - 5 && y < bottleHP.getY() + bottleHP.getHeight() + 5) {
            if (x >= bottleHP.getX() - 5 && x <= bottleHP.getX() + bottleHP.getWidth()) {
                if (isBeginFight && !isLose && !isWin) {
                    isBomMau = true;
                    TimerTask timeTask = new TimerTask() {

                        public void run() {
                            isBomMau = false;
                            if (noBottleHP > 0) {
                                noBottleHP--;
                                pet[iPet].hp += 50;
                                if (pet[iPet].hp > maxHPMe) {
                                    pet[iPet].hp = maxHPMe;
                                }
                            }
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(timeTask, 4 * delay);
                }
            }
            if (x >= bottleMP.getX() - 5 && x <= bottleMP.getX() + bottleMP.getWidth()) {
                if (isBeginFight && !isLose && !isWin) {
                    isBomMP = true;
                    TimerTask timeTask = new TimerTask() {

                        public void run() {
                            if (noBottleMP > 0) {
                                isBomMP = false;
                                noBottleMP--;
                                pet[iPet].mp += 50;
                                if (pet[iPet].mp > maxMPMe) {
                                    pet[iPet].mp = maxMPMe;
                                }
                            }
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(timeTask, 4 * delay);
                }
            }
        }
    }

    public void pointerPressedChooseArena(int x, int y) {
        pointDragX = x;
        if (iArena <= numberArena - 1) {
            if (y >= this.getHeight() - 3 * font1.getHeight() / 2) {
                if (x >= this.getWidth() / 2 - font1.stringWidth("OK") / 2 - 3 && x <= this.getWidth() / 2 + font1.stringWidth("OK") / 2 + 3) {
                    isPointOKPresse = true;
                    int w = this.getWidth();
                    TimerTask timeTask = new TimerTask() {

                        public void run() {
                            isMenuFight = true;
                            isChooseArena = false;
                            if (myArena != null) {
                                myArena.setVisible(false);
                            }
                            isPointOKPresse = false;
                            iMenuFight = 1;
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(timeTask, 4 * delay);
                }
            }
        }
    }

    public void pointerPressedUpInfoPet(int x, int y) {
        if (y > this.getHeight() - 2 * font1.getHeight()) {
            int strw = font1.stringWidth(" UP ");
            if (x > this.getWidth() / 2 - strw / 2 - 5 && x < this.getWidth() / 2 + strw / 2 + 5) {
                isPointOKPresse = true;
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        upInfoMyPet();
                        isPointOKPresse = false;
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 4 * delay);
            }
        }
//        g.fillRoundRect(this.getWidth() / 2 - strW / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() + font1.getHeight() + 5 + iUpInfo * font1.getHeight(), strW, font1.getHeight(), 5, 5);
        if (y >= pet[iPet].getY() + pet[iPet].pet.getHeight() + font1.getHeight() + 5 && y < pet[iPet].getY() + pet[iPet].pet.getHeight() + font1.getHeight() + 5 + 3 * font1.getHeight() + 5) {
            if (x > this.getWidth() / 4 && x < 3 * this.getWidth() / 4) {
                iUpInfo = (y - (pet[iPet].getY() + pet[iPet].pet.getHeight() + font1.getHeight() + 5)) / font1.getHeight();
            }
        }
    }

    public void pointerPressedUpSkill(int x, int y) {
        if (y > this.getHeight() - 2 * font1.getHeight()) {
            int strw = font1.stringWidth(" UP ");
            if (x > this.getWidth() / 2 - strw / 2 - 5 && x < this.getWidth() / 2 + strw / 2 + 5) {
                isPointOKPresse = true;
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        upSkill();
                        isPointOKPresse = false;
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 4 * delay);
            }
        }
    }

    public void pointerPressedMssBox(int x, int y) {
        String title1 = "Bạn có muốn thoát không ?";
        int off = font1.stringWidth("Bỏ qua") + 6;
        if (y >= this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5 && y <= this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 7 * font1.getHeight() / 2 + 5) {
            if (x >= this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 - off / 2 && x <= this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 + off / 2) {
                isOKMssB = true;
            }
            if (x >= this.getWidth() / 2 + font1.stringWidth(title1) / 4 - off / 2 && x <= this.getWidth() / 2 + font1.stringWidth(title1) / 4 + off / 2) {
                isOKMssB = false;
            }
            TimerTask timeTask = new TimerTask() {

                public void run() {
                    messageBoxPressed();
                }
            };
            Timer timer = new Timer();
            timer.schedule(timeTask, 4 * delay);
        }
    }

    public void pointerPressedMssSavePet(int x, int y) {
        String title1 = "Bạn sẽ tốn 1000$ cho dịch vụ";
        int off = font1.stringWidth("Bỏ qua") + 6;
        if (y >= this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 2 * font1.getHeight() + 5 && y <= this.getHeight() / 2 - (10 + 2 * font1.getHeight() + 5 + 3 * font1.getHeight() / 2) / 2 + 5 + 7 * font1.getHeight() / 2 + 5) {
            if (x >= this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 - off / 2 && x <= this.getWidth() / 2 - font1.stringWidth(title1) / 2 + font1.stringWidth(title1) / 4 + off / 2) {
                isOKSavePet = true;
            }
            if (x >= this.getWidth() / 2 + font1.stringWidth(title1) / 4 - off / 2 && x <= this.getWidth() / 2 + font1.stringWidth(title1) / 4 + off / 2) {
                isOKSavePet = false;
            }
            TimerTask timeTask = new TimerTask() {

                public void run() {
                    savePetPressed();
                }
            };
            Timer timer = new Timer();
            timer.schedule(timeTask, 4 * delay);
        }
    }

    public void pointerPressedMenuLeftRight(int x, int y) {
        if (!isLoadingWalk) {
            if (y >= this.getHeight() - font3.getHeight()) {
                if (x > this.getWidth() - font3.stringWidth("Trở về") - 5) {
                    isPointMenuRightPressed = true;
                    TimerTask timeTask = new TimerTask() {

                        public void run() {
                            menuRightKey();
                            isPointMenuRightPressed = false;
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(timeTask, 2 * delay);
                }
                if (x < font3.stringWidth("Đồng ý") + 5) {
                    isPointerMenuLeftPressed = true;
                    TimerTask timeTask = new TimerTask() {

                        public void run() {
                            try {
                                menuLeftKey();
                            } catch (IOException ex) {
                                ex.printStackTrace();
                            }
                            isPointerMenuLeftPressed = false;
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(timeTask, 2 * delay);
                }
            }
        }
    }

    public void pointerPressedInfo(int x, int y) {
        pointDragX = x;
        if (y >= arrowInfo1.getY() - 3 && y < arrowInfo1.getY() + arrowInfo1.getHeight() + 3) {
            if (x >= 0 && x <= arrowInfo1.getX() + arrowInfo1.getWidth() + 5) {
                isPointInfoLeftPress = true;
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        if (iInfo > 0) {
                            iInfo--;
                        } else {
                            iInfo = 4;
                        }
                        xState = xInfo = 0;
                        isPointInfoLeftPress = false;
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 2 * delay);
            }
            if (x <= this.getWidth() && x > arrowInfo2.getX() - 5) {
                isPointInfoRightPress = true;
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        if (iInfo < 4) {
                            iInfo++;
                        } else {
                            iInfo = 0;
                        }
                        xState = xInfo = 0;
                        isPointInfoRightPress = false;
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 2 * delay);
            }
        }
    }

    public void pointerPressedChooseEgg(int x, int y) {
        if (y >= egg1.getY() && y <= egg1.getY() + egg1.getHeight()) {
            if (x >= egg1.getX() && x <= egg1.getX() + egg1.getWidth()) {
                iEgg = 0;
            }
            if (x >= egg2.getX() && x <= egg2.getX() + egg2.getWidth()) {
                iEgg = 1;
            }
        }
        if (y >= this.getHeight() - 3 * font1.getHeight() / 2) {
            if (x >= this.getWidth() / 2 - font1.stringWidth("OK") / 2 - 3 && x <= this.getWidth() / 2 + font1.stringWidth("OK") / 2 + 3) {
                TimerTask timeTask = new TimerTask() {

                    public void run() {
                        okChooseEgg();
                        isChooseEgg = false;
//                        isStartedGame = true;
//                        initMainMap();
//                        initInfoMap();
//                        initFightMap();
                    }
                };
                Timer timer = new Timer();
                timer.schedule(timeTask, 4 * delay);
            }
        }
    }

    public void pointerPressedChoosePet(int x, int y) {
        int height = 40 + 5 + font1.getHeight() * 5;
        int width = this.getWidth() / 2 - 10;
        if (y >= this.getHeight() / 2 - height / 2 - 5 && y <= this.getHeight() / 2 + height / 2 + 5) {
            if (x > 10 && x < this.getWidth() - 10) {
                iPet = iChoosePet = (x - 10) / width;
            }
        }
        if (y > this.getHeight() - 3 * font1.getHeight() / 2) {
            if (x > this.getWidth() / 2 - 10 && x < this.getWidth() / 2 + 10) {
                if (!isSellPet && !isExitGamePressed) {
                    isPointOKPresse = true;
                    TimerTask timeTask = new TimerTask() {

                        public void run() {
                            okChoosePet();
                            isPointOKPresse = false;
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(timeTask, 4 * delay);
                }
            }
        }
    }

    protected void pointerPressed(int x, int y) {
        if (!isPlay || isCleaning) {
            return;
        }
        super.pointerPressed(x, y);
        if (isStartedGame) {
            if (!isExitPressed) {
                if (!isSavePetMss) {
                    pointDragY = y;
                    pointCaressX = x;
                    if (!isLock && !isMainBeginDown && !isMainBeginUp && !isChamsoc && !isPresentItem) {
                        if (!isOpenSubMenu && !isLock && !isWork && pointer.isVisible()) {
                            pointerPressedMainMenu(x, y);
                        } else {
                            if (isOpenSubMenu && !isWork && pointer.isVisible()) {
                                pointerPressedSubMenu(x, y);
                            }
                            if (isWork) {
                                if (isThiDau) {
                                    if (isMenuFight) {
                                        pointerPressedMenuFight(x, y);
                                    } else if (isChooseFight) {
                                        pointerPressedChooseFight(x, y);
                                    } else if (isBeginFight) {
                                        pointerPressedBeginFight(x, y);
                                        pointerPressedBomMau(x, y);
                                    } else if (isChooseArena) {
                                        pointerPressedChooseArena(x, y);
                                    } /*else if (isDrawSkillFight) {
                                    pointerPressedChooSkillFight(x, y);
                                    pointerPressedUpSkill(x, y);
                                    } else if (isInfoFight) {
                                    pointerPressedUpInfoPet(x, y);
                                    }*/
                                } else if (isTrain && !isStartTrain) {
                                    if (y <= this.getHeight() && y > trainArrow.getY() + trainArrow.getHeight() && x > this.getWidth() / 2 - 10 && x < this.getWidth() / 2 + 10) {
                                        arrowPressed();
                                    }
                                }
                            }
                        }
                    }
                } else {
                    pointerPressedMssSavePet(x, y);
                }
            } else {
                pointerPressedMssBox(x, y);
            }
            if (isInfoScreen) {
                pointerPressedInfo(x, y);
                if (iInfo == 4) {
                    pointerPressedChooSkillFight(x, y);
                    pointerPressedUpSkill(x, y);
                } else if (iInfo == 3) {
                    pointerPressedUpInfoPet(x, y);
                }
            }
        } else {
            if (isChooseEgg) {
                pointerPressedChooseEgg(x, y);
            } else {
                pointerPressedChoosePet(x, y);
            }
        }
        pointerPressedMenuLeftRight(x, y);
    }

    protected void pointerReleased(int x, int y) {
        if (!isPlay) {
            return;
        }
        super.pointerReleased(x, y);
        if (isInfoScreen) {
            if (pointDragX > x) {
                if (iInfo > 0) {
                    iInfo--;
                } else {
                    iInfo = 4;
                }
                xState = xInfo = 0;
//                pointDragX = 0;
            }
            if (pointDragX < x) {
                if (iInfo < 4) {
                    iInfo++;
                } else {
                    iInfo = 0;
                }
                xState = xInfo = 0;
//                pointDragX = 0;
            }
        } else if (isTrain && !isStartTrain) {
//            if (pointCaressX >= pet1.getX() + 5 && pointCaressX < pet1.getX() + pet1.pet.getWidth() / 2) {
//                if (x >= pet1.pet.getX() + 2 * pet1.pet.getWidth() / 3) {
//                    if (pointDragY > pet1.pet.getY() + 5 && pointDragY < pet1.getY() + pet1.pet.getHeight()) {
//                        if (y > pet1.pet.getY() + 5 && y < pet1.getY() + pet1.pet.getHeight()) {
//                            isCaress = true;
//                            pet1.noLove = 0;
//                        }
//                    }
//                }
//            }
            if (y < trainArrow.getY()) {
                if (Math.abs(y - pointDragY) < 20) {
                    if (x > pointCaressX + 5) {
                        if (iInputArrow[iArrow] == MyCanvas.ARROW_RIGHT) {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                        } else {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                            isTrainMissed = true;
                            isDrawTrainMiss = true;
                        }
                        if (iArrow < 3) {
                            iArrow++;
                        }
                        isArrowPressed = true;
                    }
                    if (x < pointCaressX - 5) {
                        if (iInputArrow[iArrow] == MyCanvas.ARROW_LEFT) {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                        } else {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                            isTrainMissed = true;
                            isDrawTrainMiss = true;
                        }
                        if (iArrow < 3) {
                            iArrow++;
                        }
                        isArrowPressed = true;
                    }
                }
                if (Math.abs(x - pointCaressX) < 20) {
                    if (y < pointDragY - 5) {
                        if (iInputArrow[iArrow] == MyCanvas.ARROW_UP) {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                        } else {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                            isTrainMissed = true;
                            isDrawTrainMiss = true;
                        }
                        if (iArrow < 3) {
                            iArrow++;
                        }
                        isArrowPressed = true;
                    }
                    if (y > pointDragY + 5) {
                        if (iInputArrow[iArrow] == MyCanvas.ARROW_DOWN) {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                        } else {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                            isTrainMissed = true;
                            isDrawTrainMiss = true;
                        }
                        if (iArrow < 3) {
                            iArrow++;
                        }
                        isArrowPressed = true;
                    }
                }
            }
        } else if (isThiDau) {
            if (isChooseArena) {
                if (y > this.getHeight() - 2 * font1.getHeight()) {
                    if (pointDragX > x + 5) {
                        if (iArena > 0) {
                            iArena--;
                        } else {
                            iArena = nameArena.length - 1;
                        }
                        if (totalMemory > 1000000 || this.getWidth() >= 200) {
                            setImageArena();
                        }
                    }
                    if (pointDragX < x - 5) {
                        if (iArena < nameArena.length - 1) {
                            iArena++;
                        } else {
                            iArena = 0;
                        }
                        if (totalMemory > 1000000 || this.getWidth() >= 200) {
                            setImageArena();
                        }
                    }
                }
            }
        }
    }

    protected void pointerDragged(int x, int y) {
        if (!isPlay) {
            return;
        }
        super.pointerDragged(x, y);
    }

    private void downKey() {
        if (!isBeginFight) {
            if (!isInfoScreen) {
                if (isTrain && !isStartTrain) {

                    if (iArrow < 4) {
                        if (iInputArrow[iArrow] == MyCanvas.ARROW_DOWN) {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                        } else {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                            isTrainMissed = true;
                            isDrawTrainMiss = true;
                        }
                        iArrow++;
                    }
                    isArrowPressed = true;
                } else if (isWork) {
                    if (isMenuFight) {
                        if (iMenuFight < 3) {
                            iMenuFight++;
                        } else {
                            iMenuFight = 0;
                        }
                    }
//                    if (isDrawSkillFight) {
//                        if (iChooseSkillFight < listChooseSkill.getRows() - 2) {
//                            iChooseSkillFight++;
//                        } else {
//                            iChooseSkillFight = 0;
//                        }
//                    }
//                    if (isInfoFight) {
//                        if (iUpInfo < costUpInfo.length - 1) {
//                            iUpInfo++;
//                        } else {
//                            iUpInfo = 0;
//                        }
//                    }
                }
            } else {
                if (iInfo == 4) {
                    if (iChooseSkillFight < listChooseSkill.getRows() - 1) {
                        iChooseSkillFight++;
                    } else {
                        iChooseSkillFight = 0;
                    }
                }
                if (iInfo == 3) {
                    if (iUpInfo < costUpInfo.length - 1) {
                        iUpInfo++;
                    } else {
                        iUpInfo = 0;
                    }
                }
            }
        } else {
            if (iSkill < 5) {
                iSkill += 5;
            } else {
                iSkill -= 5;
            }
        }
    }

    private void fireKey() {
        if (isStartedGame) {
            if (!isStartWalk) {
                if (!isExitPressed) {
                    if (!isSavePetMss) {
                        if (!isOpenSubMenu && !isLock && !isWork && pointer.isVisible()) {
                            mainMenuPressed();
                            if (isInfoScreen) {
                                if (iInfo == 3) {
                                    upInfoMyPet();
                                } else if (iInfo == 4) {
                                    upSkill();
                                }
                            }
                        } else {
                            if (isOpenSubMenu && !isWork && pointer.isVisible()) {
                                subMenuPressed();
                            }
                            if (isWork) {
                                if (isTrain && !isStartTrain) {
                                    arrowPressed();
                                } else if (isThiDau) {
                                    if (isMenuFight) {
                                        menuFightPressed();
                                    } else {
//                                        if (isInfoFight) {
//                                            upInfoMyPet();
//                                        }
                                        if (isChooseFight) {
                                            okChooseFight();
                                        } else if (isBeginFight) {
//                                        if (!isHitting && !reHitting && isYourTurn && !isTrailer) {
                                            okSkillFight();
//                                        }
                                        } else if (isChooseArena) {
                                            if (iArena <= numberArena - 1) {
                                                setInfoDoiThu(iArena);
                                                isMenuFight = true;
                                                isChooseArena = false;
                                                if (totalMemory > 1000000 || this.getWidth() >= 200) {
                                                    myArena.setVisible(false);
                                                }
                                                iMenuFight = 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        savePetPressed();
                    }
                } else {
                    messageBoxPressed();
                }
            } else {
                if (isCollidesPet) {
                    okFightPetWalk();
                    isCollidesPet = false;
                }
            }
        } else {
            if (isChooseEgg) {
                okChooseEgg();
                isChooseEgg = false;
            } else {
                if (!isSellPet) {
                    okChoosePet();
                }
            }
        }
    }

    public void messageBoxPressed() {
        if (isOKMssB) {
            isExitPressed = false;
            isStartedGame = false;
            isChooseEgg = false;
            isOKMssB = false;
            pointer.setVisible(true);
        } else {
            isOKMssB = false;
            isExitPressed = false;
            pointer.setVisible(true);
        }
    }

    public void savePetPressed() {
        System.out.println("Save");
        if (!isOKSavePet) {
            isSavePetMss = false;
        } else {
            if (money >= moneySavePet) {
                money -= moneySavePet;
                this.saveInfoPet(iPet);
                isSavePetMss = false;
                isSavePetSuccess = true;
                isSavedPet = true;
            }
        }
    }

    public void mainMenuPressed() {
        if (!isPresentItem && !isDrawAnouce) {
            if (iMainMenu == 0 || iMainMenu == 2) {
                isMainBeginDown = true;
                for (int i = 0; i < mainMenu.length; i++) {
                    mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), topMainMenu);
                }
                iSubMenu1 = iSubMenu2 = iSubMenu3 = iPointer = 0;
            }
            if (iMainMenu == 3 && !isInfoScreen) {
                isInfoScreen = true;
                iInfo = 0;
            }
            if (iMainMenu == 1 && !isDrawAnouce) {
                if (pet[iPet].level >= 2/* && pet[iPet].getState() != Pet.STATE_PHOENIX*/) {
                    if (this.getWidth() <= 200) {
                        if (this.getWidth() > 160) {
                            addMainScreen.fillCells(0, 0, 1, addMainScreen.getRows(), 0);
                        }
                        pet[iPet].pet.setVisible(false);
                        isThiDau = true;
                        isMenuFight = true;
                        iMenuFight = 0;
                        isChoosen = false;
                        pet[iPet].pet.setFrame(0);
                        yMenuFight = 0;
                        if (totalMemory < 1000000) {
                            setNullImageChick();
                        }
//                        if (this.getWidth() < 160 && totalMemory < 1000000) {
//                            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
//                                pet[iPet].setImage(gameDesign.getGa_con_chien_dau128(), 25, 25);
//                            }
//                            if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
//                                pet[iPet].setImage(gameDesign.getGa_trungbinh_chien_dau128(), 40, 40);
//                            }
//                            if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
//                                pet[iPet].setImage(gameDesign.getGa_lon_chien_dau128(), 45, 45);
//                            }
//                        }
                        try {
                            gameMedia.stop();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    } else {
                        isLoadingWalk = true;
                        thinking.setVisible(false);
                        iconThinking.setVisible(false);
                    }
                } else {
                    isCanFight = true;
                }
            }
            if (iMainMenu == mainMenu.length - 1) {
                isSavePetMss = true;
            }
        }
    }

    public void subMenuPressed() {
        if (iMainMenu == 0) {
            if (iSubMenu1 == 0) {
                if (pet[iPet].cleanPoint <= 0) {
                    isCleaning = true;
                    broom.setVisible(true);
                    dust.setVisible(true);
                    broom.setPosition(pet[iPet].getX() + pet[iPet].pet.getWidth() / 2 - broom.getWidth() / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - broom.getHeight() / 2);
                    dust.setPosition(broom.getX() - 4, broom.getY() + 7);
                    pointer.setVisible(false);
                    iconThinking.setVisible(false);
                    thinking.setVisible(false);
                    pet[iPet].cleanPoint += 100;
                } else {
                    isDrawNoCareClean = true;
                    face.setFrameSequence(gameDesign.faceseq002);
                    timeDrawNoCare = 0;
                }
            }
            if (iSubMenu1 == 1) {
                if (noFood > 0) {
                    if (pet[iPet].foodPoint <= 0) {
                        isEating = true;
                        face.setVisible(true);
                        pet[iPet].pet.setVisible(false);
                        pointer.setVisible(false);
                        iconThinking.setVisible(false);
                        thinking.setVisible(false);
                        pet[iPet].foodPoint += 100;
                        face.setFrameSequence(gameDesign.faceseq001);
                    } else {
                        isDrawNoCareEat = true;
                        face.setFrameSequence(gameDesign.faceseq002);
                        timeDrawNoCare = 0;
                    }
                } else {
                    isDrawEmptyFood = true;
                    face.setFrameSequence(gameDesign.faceseq002);
                    timeDrawNoCare = 0;
                }
            }
            if (iSubMenu1 == 2) {
                if (pet[iPet].learnPoint <= 0) {
                    isLearning = true;
                    pencil.setVisible(true);
                    noteBook.setVisible(true);
                    noteBook.setPosition(pet[iPet].pet.getX(), pet[iPet].pet.getY());
                    pencil.setPosition(noteBook.getX(), noteBook.getY() - 10);
                    pointer.setVisible(false);
                    iconThinking.setVisible(false);
                    thinking.setVisible(false);
                    pet[iPet].learnPoint += 100;
                } else {
                    isDrawNoCareLearn = true;
                    face.setFrameSequence(gameDesign.faceseq002);
                    timeDrawNoCare = 0;
                }
            }
            if (iSubMenu1 == 3) {
                isTrain = true;
                for (int i = 0; i < subMenu1.length; i++) {
                    subMenu1[i].setVisible(false);
                }
                scoreTrain = 0;
                isStartTrain = true;
                pointer.setVisible(false);
                trainArrow.setVisible(true);
                isTrainBeginUp = true;
                xLight = trainArrow.getX();
                if (pet[iPet].level < 5) {
                    timeTrain = 120000;
                } else if (pet[iPet].level < 10) {
                    timeTrain = 180000;
                } else {
                    timeTrain = 240000;
                }
                randomTrainArrow();
                thinking.setVisible(false);
                iconThinking.setVisible(false);
                pet[iPet].pet.setFrame(0);
            }
            if (iSubMenu1 == 4) {
                if (pet[iPet].helthPoint <= 0) {
                    isDoctor = true;
                    doctor.setVisible(true);
                    pointer.setVisible(false);
                    iconThinking.setVisible(false);
                    thinking.setVisible(false);
                    pet[iPet].helthPoint += 100;
                } else {
                    isDrawNoCareDoctor = true;
                    face.setFrameSequence(gameDesign.faceseq002);
                    timeDrawNoCare = 0;
                }
            }
            if (isDrawNoCareClean || isDrawNoCareDoctor || isDrawNoCareEat || isDrawNoCareLearn || isDrawEmptyFood) {
                face.setVisible(true);
                pet[iPet].pet.setVisible(false);
                pointer.setVisible(false);
            }
        }
        if (iMainMenu == 2) {
            if (iSubMenu3 == 0) {
//                money += 1000;
                addGold();
            }
            if (iSubMenu3 == 1) {
                if (money >= 200) {
                    noFood += 1;
                    money -= 200;
                    isBuyFood = true;
                    yNotEnoughMoney = pet[iPet].getY();
                } else {
                    isNotEnoughMoneyBuyFood = true;
                }
            }
            if (iSubMenu3 == 2) {
                if (money >= 400) {
                    noBottleHP += 1;
                    money -= 400;
                    yNotEnoughMoney = pet[iPet].getY();
                    isBuyHP = true;
                } else {
                    isNotEnoughMoneyBuyFood = true;
                }
            }
            if (iSubMenu3 == 3) {
                if (money >= 500) {
                    noBottleMP += 1;
                    money -= 500;
                    yNotEnoughMoney = pet[iPet].getY();
                    isBuyMP = true;
                } else {
                    isNotEnoughMoneyBuyFood = true;
                }
            }
        }
    }

    public void arrowPressed() {
        if (isTrain) {
            if (isTrainMissed) {
                randomTrainArrow();
                isDrawTrainMiss = false;
                scoreTrain -= 10;
            } else {
                if (xLight > (trainArrow.getX() + 3 * trainArrow.getWidth() / 4 - lightTrain.getWidth()) && xLight < trainArrow.getX() + 3 * trainArrow.getWidth() + 8) {
                    if (iArrow == 4) {
                        isTrainMissed = false;
                        pet[iPet].isDance = true;
                        scoreTrain += 10;
                        if (pet[iPet].level >= 0) {
                            skillTrain += 10;
                            if (skillTrain == 50) {
                                pet[iPet].skillPoint += 1;
                                skillTrain = 0;
                                isAddSkillTrain = true;
                            }
                        }
                        isDrawTrainFinish = true;
                        randomTrainArrow();
                    } else {
                        isTrainMissed = true;
                        isDrawTrainMiss = true;
                    }
                    timeTrainFinish = 0;
                    timeAddSkillTrain = pet[iPet].getY();
                    if (pet[iPet].relaxPoint <= 0) {
                        if (scoreTrain >= needScoreTrain) {
                            pet[iPet].relaxPoint += 100;
                        }
                    }
                } else {
                    if (isArrowPressed) {
                        randomTrainArrow();
                        scoreTrain -= 10;
                        isDrawTrainMiss = true;
                    } else {
                        randomTrainArrow();
                    }
                }
            }
        }
    }

    public void menuFightPressed() {
        if (iMenuFight == 3) {
            timeDrawYourTurn = 0;
            isMenuFight = false;
            isThiDau = false;
            if (this.getWidth() >= 200) {
                isStartWalk = true;
            }
            try {
                fightMedia.stop();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            pet[iPet].pet.setVisible(true);
            if (!isThiDau) {
                try {
                    if (pet[iPet].getState() >= 3) {
                        if (this.getWidth() >= 200) {
//                            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
//                                pet[iPet].setImage(gameDesign.getGaCon(), 40, 40);
//                            }
//                            if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
//                                pet[iPet].setImage(gameDesign.getGaTrungBinh(), 60, 60);
//                            }
//                            if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
//                                pet[iPet].setImage(gameDesign.getGaLon(), 70, 70);
//                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                                pet[iPet].setImage(gameDesign.getGaCon128(), 25, 25);
                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
                                pet[iPet].setImage(gameDesign.getGaTrungBinh128(), 40, 40);
                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
                                pet[iPet].setImage(gameDesign.getGaLon128(), 45, 45);
                            }
                        } else {
                            if (this.getWidth() < 160 && totalMemory < 1000000) {
                                setNullImageChickFight();
                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                                pet[iPet].setImage(gameDesign.getGaCon128(), 25, 25);
                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
                                pet[iPet].setImage(gameDesign.getGaTrungBinh128(), 40, 40);
                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
                                pet[iPet].setImage(gameDesign.getGaLon128(), 45, 45);
                            }
                        }
                        pet[iPet].pet.setTransform(Sprite.TRANS_NONE);
                        if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                            pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyseq);
                        }
                        if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
                            pet[iPet].pet.setFrameSequence(pet[iPet].chickMediumseq);
                        }
                        if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
                            pet[iPet].pet.setFrameSequence(pet[iPet].chickMediumseq);
                        }
                    } else {
                        if (this.getWidth() >= 200) {
                            pet[iPet].setImage(gameDesign.getTrungga(), 26, 40);
                        } else {
                            pet[iPet].setImage(gameDesign.getTrungga(), 16, 25);
                        }
                        pet[iPet].pet.setTransform(Sprite.TRANS_NONE);
                        pet[iPet].pet.setFrameSequence(pet[iPet].chickEggSwayseq);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            if (this.getWidth() < 200) {
                pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
            } else {
                pet[iPet].setPosition(oldX, oldY);
            }
            isWork = false;
            iArena = 0;
            key.setVisible(false);
            if (myArena != null) {
                try {
                    if (this.getWidth() >= 160) {
                        myArena.setImage(gameDesign.getDau_truong1(), 240, 160);
                        doithuArena.setImage(gameDesign.getDau_truong1(), 240, 160);
                    } else {
                        myArena.setImage(gameDesign.getDau_truong1128(), 128, 100);
                        doithuArena.setImage(gameDesign.getDau_truong1128(), 128, 100);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
//        if (iMenuFight == 0) {
//            isMenuFight = false;
//            isInfoFight = true;
//        }
//        if (iMenuFight == 3) {
//            isMenuFight = false;
//            isChooseFight = true;
//            setInfoDoiThu(iArena);
//        }
        if (iMenuFight == 0) {
            isMenuFight = false;
            isChooseArena = true;
            if (totalMemory > 1000000 || this.getWidth() >= 200) {
                myArena.setVisible(true);
                if (this.getWidth() >= 200) {
                    myArena.setPosition(0, 15 + font2.getHeight());
                } else {
                    myArena.setPosition(0, 5 + font3.getHeight());
                }
            }
        }
        if (iMenuFight == 1) {
            if (this.getWidth() >= 200) {
                isMenuFight = false;
                isDrawInfoDoiThu = true;
            } else {
                isMenuFight = false;
                isChooseFight = true;
//                setInfoDoiThu(iArena);
            }
        }
        if (iMenuFight == 2) {
            if (isChoosen) {
                try {
                    if (this.getWidth() >= 200) {
                        if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                            pet[iPet].setImage(gameDesign.getGa_con_chien_dau(), 40, 40);
                        }
                        if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
                            pet[iPet].setImage(gameDesign.getGa_trungbinh_chien_dau(), 60, 60);
                        }
                        if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
                            pet[iPet].setImage(gameDesign.getGa_lon_chien_dau(), 70, 70);
                        }
                    } else {
                        if (totalMemory >= 1000000) {
                            if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                                pet[iPet].setImage(gameDesign.getGa_con_chien_dau128(), 25, 25);
                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
                                pet[iPet].setImage(gameDesign.getGa_trungbinh_chien_dau128(), 40, 40);
                            }
                            if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
                                pet[iPet].setImage(gameDesign.getGa_lon_chien_dau128(), 45, 45);
                            }
                        } else {
                            pet[iPet].setImage(gameDesign.getGa_con_chien_dau128(), 25, 25);
                        }
                    }
//                    if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
//                        pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq001);
//                    } else {
//                        pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq);
//                    }
                    pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq001);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                isTrailer = true;
                timeTrailer = 0;
                isMenuFight = false;
                isBeginFight = true;
                maxHPDoiThu = petDoiThu.hp;
                maxMPMe = pet[iPet].mp;
                maxHPMe = pet[iPet].hp;
                maxMPDoiThu = petDoiThu.mp;
                pet[iPet].pet.setTransform(Sprite.TRANS_MIRROR);
                pet[iPet].pet.setPosition(0 - pet[iPet].pet.getWidth(), this.getHeight() / 2 + this.getHeight() / 4 - pet[iPet].pet.getHeight() / 2);
                doithuBottleHP = doithuBottleMP = petDoiThu.level;
                if (pet[iPet].level <= petDoiThu.level) {
                    isYourTurn = true;
                    if (this.getWidth() > 200) {
                        curYFight = 2 * myArena.getHeight() - this.getHeight();
                    } else {
                        if (totalMemory > 1000000) {
                            curYFight = 2 * myArena.getHeight() - this.getHeight();
                        } else {
                            curYFight = 2 * 100 - this.getHeight();
                        }
                    }
                } else {
                    listSkill.setVisible(true);
                    addSkill.setVisible(true);
                    isSetVisibleCreat = false;
                    timeWaitReHit = 0;
                    curYFight = 0;
                    isYourTurn = false;
                    reHitting = true;
                    isHitting = false;
                    isAttack = true;
                    hit.setPosition(this.getWidth() - petDoiThu.pet.getWidth() - 10 + hit.getWidth(), petDoiThu.getY() - (hit.getHeight() / 2 - petDoiThu.pet.getHeight() / 2));
                    hit.setVisible(false);
                    randomReSkillFight();
                    if (this.getWidth() > 160) {
                        myWind.setPosition(0, this.getHeight() / 2);
                        doithuWind.setPosition(0, 0);
//                        myWind.setPosition(0, myArena.getY());
//                        doithuWind.setPosition(0, doithuArena.getY() - (doithuWind.getHeight() - doithuArena.getHeight()));
                    }
                    listSkill.setVisible(false);
//                    creatHit.setPosition(petDoiThu.getX() - (creatHit.getWidth() - petDoiThu.pet.getWidth()), petDoiThu.getY() - (creatHit.getHeight() / 2 - petDoiThu.pet.getHeight() / 2));
//                    creatHit.setVisible(false);
//                    hit.setPosition(creatHit.getX() - hit.getWidth(), creatHit.getY());
//                    hit.setVisible(false);
//                    oneHit.setPosition(pet[iPet].getX() - oneHit.getWidth() / 2 + pet[iPet].pet.getWidth() / 2, pet[iPet].getY() - (oneHit.getHeight() / 2 - pet[iPet].pet.getHeight() / 2));
                }
                if (this.getWidth() > 160) {
                    addNenFight.setVisible(true);
                }
                oneHit.setPosition(10 - oneHit.getWidth() / 2 + pet[iPet].pet.getWidth() / 2, pet[iPet].getY() - (oneHit.getHeight() / 2 - pet[iPet].pet.getHeight() / 2));
                petDoiThu.pet.setPosition(this.getWidth(), this.getHeight() / 4 - petDoiThu.pet.getHeight() / 2);
            } else {
                isAlert = true;
            }
        }
    }

    public void okChooseFight() {
//        setNullImageChickFight();
        if (iArena == 0) {
            try {
                if (this.getWidth() >= 200) {
//                    petDoiThu = new Pet(new Sprite(gameDesign.getGa_con_chien_dau(), 40, 40), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                    petDoiThu = new Pet(new Sprite(gameDesign.getGa_con_chien_dau(), 40, 40), petDoiThu1[iChooseFight].level, petDoiThu1[iChooseFight].mp, petDoiThu1[iChooseFight].hp, petDoiThu1[iChooseFight].skillPoint, petDoiThu1[iChooseFight].attack, petDoiThu1[iChooseFight].defend, petDoiThu1[iChooseFight].cost);
                } else {
                    if (totalMemory > 1000000) {
                        petDoiThu = new Pet(new Sprite(gameDesign.getGa_con_chien_dau128(), 25, 25), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                    } else {
                        if (petDoiThu == null) {
                            petDoiThu = new Pet(new Sprite(gameDesign.getGa_con_chien_dau128(), 25, 25), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                        }
                    }
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            petDoiThu.setState(Pet.STATE_CHICK_SMALL, petDoiThu.chickBabyFightseq001);
        } else if (iArena == 1) {
            try {
                if (this.getWidth() >= 200) {
                    petDoiThu = new Pet(new Sprite(gameDesign.getGa_trungbinh_chien_dau(), 60, 60), petDoiThu1[iChooseFight].level, petDoiThu1[iChooseFight].mp, petDoiThu1[iChooseFight].hp, petDoiThu1[iChooseFight].skillPoint, petDoiThu1[iChooseFight].attack, petDoiThu1[iChooseFight].defend, petDoiThu1[iChooseFight].cost);
//                    petDoiThu = new Pet(new Sprite(gameDesign.getGa_trungbinh_chien_dau(), 60, 60), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                } else {
                    if (totalMemory > 1000000) {
                        petDoiThu = new Pet(new Sprite(gameDesign.getGa_trungbinh_chien_dau128(), 40, 40), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                    } else {
                        if (petDoiThu == null) {
                            petDoiThu = new Pet(new Sprite(gameDesign.getGa_con_chien_dau128(), 25, 25), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                        }
                    }
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            petDoiThu.setState(Pet.STATE_CHICK_MEDIUM, petDoiThu.chickBabyFightseq001);
        } else if (iArena >= 2) {
            try {
                if (this.getWidth() >= 200) {
                    petDoiThu = new Pet(new Sprite(gameDesign.getGa_lon_chien_dau(), 70, 70), petDoiThu1[iChooseFight].level, petDoiThu1[iChooseFight].mp, petDoiThu1[iChooseFight].hp, petDoiThu1[iChooseFight].skillPoint, petDoiThu1[iChooseFight].attack, petDoiThu1[iChooseFight].defend, petDoiThu1[iChooseFight].cost);
//                    petDoiThu = new Pet(new Sprite(gameDesign.getGa_lon_chien_dau(), 70, 70), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                } else {
                    if (totalMemory > 1000000) {
                        petDoiThu = new Pet(new Sprite(gameDesign.getGa_lon_chien_dau128(), 45, 45), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                    } else {
                        if (petDoiThu == null) {
                            petDoiThu = new Pet(new Sprite(gameDesign.getGa_con_chien_dau128(), 25, 25), infoDoithu[iChooseFight][0], infoDoithu[iChooseFight][1], infoDoithu[iChooseFight][2], infoDoithu[iChooseFight][3], infoDoithu[iChooseFight][4], infoDoithu[iChooseFight][5]);
                        }
                    }
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            petDoiThu.setState(Pet.STATE_CHICK_BIG, petDoiThu.chickBabyFightseq001);
        }
        if (this.getWidth() >= 200) {
            setAccDoiThu(iChooseFight % 5);
        } else {
            setAccDoiThu(iChooseFight % 5);
        }
        doithuBottleMP = doithuBottleHP = petDoiThu.level;
        isChooseFight = false;
        isMenuFight = true;
        iMenuFight = 2;
        isChoosen = true;
        isAlert = false;
        lmFight.remove(petDoiThu.pet);
        lmFight.insert(petDoiThu.pet, 0);
        lmFight.remove(oneHit);
        lmFight.insert(oneHit, 0);
        oneHit.setVisible(false);
        lmFight.remove(oneHitPhandon);
        lmFight.insert(oneHitPhandon, 0);
        oneHitPhandon.setVisible(false);
        choosenFight.setVisible(false);
        petDoiThu.pet.setVisible(false);
        petDoiThu.pet.setPosition(this.getWidth() - petDoiThu.pet.getWidth() - 10, this.getHeight() / 4 - petDoiThu.pet.getHeight() / 2);
    }

    public void okFightPetWalk() {
        oldX = pet[iPet].getX();
        oldY = pet[iPet].getY();
        if (this.getWidth() > 160) {
            addMainScreen.fillCells(0, 0, 1, addMainScreen.getRows(), 0);
        }
        pet[iPet].pet.setVisible(false);
        isThiDau = true;
        isMenuFight = true;
        iMenuFight = 0;
        isChoosen = true;
        pet[iPet].pet.setFrame(0);
        yMenuFight = 0;
        isStartWalk = false;
        if (iChooseFight < 5) {
            iArena = 0;
        } else if (iChooseFight < 10) {
            iArena = 1;
        } else if (iChooseFight < 15) {
            iArena = 2;
        } else if (iChooseFight < 20) {
            iArena = 3;
        }
        okChooseFight();
        iArena = 0;
        iMenuFight = 0;
        try {
            gameMedia.stop();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void upSkill() {
        if (iChooseSkillFight < 6) {
            if (isUseSkill[iChooseSkillFight] && skilllv[iChooseSkillFight] < 3) {
                if (money >= costSkill[iChooseSkillFight] && pet[iPet].skillPoint >= spSkill[iChooseSkillFight]) {
                    money -= costSkill[iChooseSkillFight];
                    pet[iPet].skillPoint -= spSkill[iChooseSkillFight];
//                mana[], dam[], acc[], doithuAcc[], skilllv[], costSkill[], spSkill[]
                    mana[iChooseSkillFight] += 5;
                    skilllv[iChooseSkillFight] += 1;
                    costSkill[iChooseSkillFight] = (iChooseSkillFight * 2 + 2) * 500 + 2 * skilllv[iChooseSkillFight] * 500;
//                    if (iChooseSkillFight <= 3) {
//                        spSkill[iChooseSkillFight] += 10;
//                    } else if (iChooseSkillFight < 6) {
//                        spSkill[iChooseSkillFight] += 20;
//                    } else {
//                        spSkill[iChooseSkillFight] += 30;
//                    }
                    for (int i = 0; i < spSkill.length; i++) {
                        if (i <= 3) {
                            spSkill[i] = 50 + 5 * 2 * (skilllv[i] - 1);
                        } else if (i < 6) {
                            spSkill[i] = 50 + 10 * 2 * (skilllv[i] - 1);
                        } else {
                            spSkill[i] = 50 + 15 * 2 * (skilllv[i] - 1);
                        }
                    }
                    if (iChooseSkillFight < 6) {
                        dam[iChooseSkillFight] += 1;
                    }
                    if (iChooseSkillFight < 6) {
                        if (acc[iChooseSkillFight] == 30) {
                            acc[iChooseSkillFight] = 50;
                        } else if (acc[iChooseSkillFight] == 50) {
                            acc[iChooseSkillFight] = 100;
                        }
                    }
                }
            }
        }
    }

    public void randomReSkillFight() {
        try {
            randomReBuffSkill9();
//            if (!isWin && !isLose) {
//                if (petDoiThu.mp <= mana[1]) {
//                    if (doithuBottleMP > 0) {
//                        petDoiThu.mp += 50;
//                        doithuBottleMP--;
//                        if (petDoiThu.mp > maxMPDoiThu) {
//                            petDoiThu.mp = maxMPDoiThu;
//                        }
//                    }
//                }
//                if (petDoiThu.hp < maxHPDoiThu / 2) {
//                    if (doithuBottleHP > 0) {
//                        petDoiThu.hp += 50;
//                        doithuBottleHP--;
//                        if (petDoiThu.hp > maxHPDoiThu) {
//                            petDoiThu.hp = maxHPDoiThu;
//                        }
//                    }
//                }
//            }
            iRe = r.nextInt(/*listSkill.getColumns()*/6);
            while (petDoiThu.mp < mana[iRe]) {
                iRe = r.nextInt(/*listSkill.getColumns()*/6);
            }
            if (iArena == 3) {
                if (iRe == 5) {
                    iRe = 0;
                }
            }
//            if (totalMemory > 1000000 || this.getWidth() >= 200) {
//                setNullImageSkill();
//            }
            if (this.getWidth() < 160) {
                if (totalMemory < 1000000) {
                    setNullImageSkill();
                }
            }
            if (iRe == 0) {
                petDoiThu.pet.setFrameSequence(petDoiThu.chickBabyFightseq001);
                if (this.getWidth() >= 200) {
                    hit.setImage(gameDesign.getGa_skill1(), 60, 60);
                } else {
                    hit.setImage(gameDesign.getGa_skill1128(), 40, 40);
                }
            }
            if (iRe == 1 || iRe == 2) {
                petDoiThu.pet.setFrameSequence(petDoiThu.chickBabyFightseq003);
                if (this.getWidth() >= 200) {
                    hit.setImage(gameDesign.getGa_skill3(), 60, 60);
                } else {
                    hit.setImage(gameDesign.getGa_skill3128(), 40, 40);
                }
            }
            if (iRe == 4) {
                petDoiThu.pet.setFrameSequence(petDoiThu.chickBabyFightseq002);
                if (this.getWidth() >= 200) {
                    hit.setImage(gameDesign.getGa_skill5(), 60, 60);
                } else {
                    hit.setImage(gameDesign.getGa_skill5128(), 40, 40);
                }
//                hit.setPosition(petDoiThu.getX() - (hit.getWidth() - petDoiThu.pet.getWidth()), petDoiThu.getY());
            }
            if (iRe == 3) {
                petDoiThu.pet.setFrameSequence(petDoiThu.chickBabyFightseq003);
                if (this.getWidth() >= 200) {
                    hit.setImage(gameDesign.getGa_skill4(), 60, 60);
                } else {
                    hit.setImage(gameDesign.getGa_skill4128(), 40, 40);
                }
//                hit.setPosition(petDoiThu.getX() - (hit.getWidth() - petDoiThu.pet.getWidth()), petDoiThu.getY());
            }
            if (iRe == 5) {
                petDoiThu.pet.setFrameSequence(petDoiThu.chickBabyFightseq005);
                if (this.getWidth() >= 200) {
                    hit.setImage(gameDesign.getGa_skill6(), 60, 60);
                } else {
                    hit.setImage(gameDesign.getGa_skill6128(), 40, 40);
                }
                int[] seq = {0, 0, 1, 1, 1, 2, 2, 2, 2, 2};
                hit.setFrameSequence(seq);
                lmFight.remove(hit);
                lmFight.insert(hit, 0);
                hit.setPosition(pet[iPet].getX() - (hit.getWidth() / 2 - pet[iPet].pet.getWidth() / 2), pet[iPet].getY());
            }
//            oneHit.setPosition(pet[iPet].getX() - (oneHit.getWidth() / 2 - pet[iPet].pet.getWidth() / 2) /*+ oneHit.getWidth() / 2*/, pet[iPet].getY() - (oneHit.getHeight() / 2 - pet[iPet].pet.getHeight() / 2));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void randomReBuffSkill() {
        try {
            int random = r.nextInt(5);
            int minMP = Math.min(Math.min(mana[6], mana[7]), mana[9]);
            if (random == 1) {
                if (petDoiThu.mp >= minMP) {
//                    if (totalMemory > 1000000 || this.getWidth() >= 200) {
//                        setNullImageSkill();
//                    }
                    if (this.getWidth() < 160) {
                        if (totalMemory < 1000000) {
                            setNullImageSkill();
                        }
                    }
                    iReBuffSkill = r.nextInt(3);
                    if (iReBuffSkill == 0) {
                        if (petDoiThu.mp >= mana[6]) {
                            lmFight.remove(doithuBuffSkill);
                            lmFight.insert(doithuBuffSkill, 0);
                            if (this.getWidth() >= 200) {
                                doithuBuffSkill.setImage(gameDesign.getGa_skill7(), 60, 60);
                            } else {
                                doithuBuffSkill.setImage(gameDesign.getGa_skill7128(), 40, 40);
                            }
                            doithuBuffSkill.setFrameSequence(gameDesign.chickBabySkill7seq001);
                            doithuBuffSkill.setPosition(petDoiThu.getX() - (doithuBuffSkill.getWidth() - petDoiThu.pet.getWidth()) / 2, petDoiThu.getY() - (doithuBuffSkill.getHeight() - petDoiThu.pet.getHeight()) / 2);
                            doithuBuffSkill.setVisible(true);
                            isReSkill7 = true;
                            petDoiThu.mp -= mana[6];
                        }
                    }
                    if (iReBuffSkill == 1) {
                        if (petDoiThu.mp >= mana[7]) {
                            lmFight.remove(doithuBuffSkill);
                            lmFight.insert(doithuBuffSkill, 0);
                            if (this.getWidth() >= 200) {
                                doithuBuffSkill.setImage(gameDesign.getGa_skill8(), 60, 60);
                            } else {
                                doithuBuffSkill.setImage(gameDesign.getGa_skill8128(), 40, 40);
                            }
                            doithuBuffSkill.setFrameSequence(gameDesign.chickBabySkill8seq001);
                            doithuBuffSkill.setPosition(petDoiThu.getX() - (doithuBuffSkill.getWidth() - petDoiThu.pet.getWidth()) / 2, petDoiThu.getY() - (doithuBuffSkill.getHeight() - petDoiThu.pet.getHeight()) / 2);
                            doithuBuffSkill.setVisible(true);
                            isReSkill8 = true;
                            petDoiThu.mp -= mana[7];
                        }
                    }
                    if (iReBuffSkill == 2) {
                        if (petDoiThu.mp >= mana[9]) {
                            lmFight.remove(doithuBuffSkill);
                            lmFight.insert(doithuBuffSkill, 0);
                            if (this.getWidth() >= 200) {
                                doithuBuffSkill.setImage(gameDesign.getGa_skill10(), 60, 60);
                            } else {
                                doithuBuffSkill.setImage(gameDesign.getGa_skill10128(), 40, 40);
                            }
                            doithuBuffSkill.setFrameSequence(gameDesign.chickBabySkill10seq001);
                            doithuBuffSkill.setPosition(petDoiThu.getX() - (doithuBuffSkill.getWidth() - petDoiThu.pet.getWidth()) / 2, petDoiThu.getY() - (doithuBuffSkill.getHeight() - petDoiThu.pet.getHeight()) / 2);
                            doithuBuffSkill.setVisible(true);
                            isReSkill10 = true;
                            petDoiThu.mp -= mana[9];
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void randomReBuffSkill9() {
        try {
            int random = r.nextInt(5);
            if (random == 1) {
                if (petDoiThu.mp >= mana[8]) {
//                    if (totalMemory > 1000000 || this.getWidth() >= 200) {
//                        setNullImageSkill();
//                    }
                    if (this.getWidth() < 160) {
                        if (totalMemory < 1000000) {
                            setNullImageSkill();
                        }
                    }
                    lmFight.remove(doithuBuffSkill);
                    lmFight.insert(doithuBuffSkill, 13);
                    if (this.getWidth() >= 200) {
                        doithuBuffSkill.setImage(gameDesign.getGa_skill9(), 60, 60);
                    } else {
                        doithuBuffSkill.setImage(gameDesign.getGa_skill9128(), 40, 40);
                    }
                    doithuBuffSkill.setFrameSequence(gameDesign.chickBabySkill9seq001);
                    doithuBuffSkill.setPosition(petDoiThu.getX() - (doithuBuffSkill.getWidth() - petDoiThu.pet.getWidth()) / 2, petDoiThu.getY() - (doithuBuffSkill.getHeight() - petDoiThu.pet.getHeight()) / 2);
                    doithuBuffSkill.setVisible(true);
                    isReSkill9 = true;
                    petDoiThu.mp -= mana[8];
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void okSkillFight() {
        try {
            if (iSkill < numberSkill) {
                if (!isHitting && !reHitting && isYourTurn && !isTrailer) {
                    if (iSkill <= 5) {
                        if (pet[iPet].mp >= mana[iSkill]) {
                            if (this.getWidth() < 160) {
                                if (totalMemory < 1000000) {
                                    setNullImageSkill();
                                }
                            }
                            if (iSkill == 0) {
                                if (this.getWidth() >= 200) {
                                    hit.setImage(gameDesign.getGa_skill1(), 60, 60);
                                } else {
                                    hit.setImage(gameDesign.getGa_skill1128(), 40, 40);
                                }
                                int[] seq = {0, 1, 2};
                                hit.setFrameSequence(seq);
                                hit.setVisible(false);
                                if (pet[iPet].state != Pet.STATE_PHOENIX) {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq001);
                                } else {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].phoenixFightseq);
                                }
                                if (iArena == 0) {
                                    pet[iPet].mp -= mana[iSkill];
                                }
                                if (iArena == 1) {
                                    pet[iPet].mp -= 2 * mana[iSkill] / 3;
                                }
                                if (iArena == 2) {
                                    pet[iPet].mp -= 2 * mana[iSkill];
                                }
                                if (iArena == 3) {
                                    pet[iPet].mp -= mana[iSkill] / 2;
                                }
                            }
                            if (iSkill == 1) {
                                if (this.getWidth() >= 200) {
                                    hit.setImage(gameDesign.getGa_skill2(), 60, 60);
                                } else {
                                    hit.setImage(gameDesign.getGa_skill2128(), 40, 40);
                                }
                                hit.setFrameSequence(gameDesign.chickBabySkill2seq001);
                                hit.setPosition(pet[iPet].getX(), pet[iPet].getY());
                                hit.setVisible(false);
                                if (pet[iPet].state != Pet.STATE_PHOENIX) {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq004);
                                } else {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].phoenixFightseq);
                                }
                                if (iArena == 0) {
                                    pet[iPet].mp -= mana[iSkill];
                                }
                                if (iArena == 1) {
                                    pet[iPet].mp -= 2 * mana[iSkill] / 3;
                                }
                                if (iArena == 2) {
                                    pet[iPet].mp -= 2 * mana[iSkill];
                                }
                                if (iArena == 3) {
                                    pet[iPet].mp -= mana[iSkill] / 2;
                                }
                                isCheckHit2 = true;
                            }
                            if (iSkill == 2) {
                                if (this.getWidth() >= 200) {
                                    hit.setImage(gameDesign.getGa_skill3(), 60, 60);
                                } else {
                                    hit.setImage(gameDesign.getGa_skill3128(), 40, 40);
                                }
                                int[] seq = {0, 1, 2};
                                hit.setFrameSequence(seq);
                                hit.setVisible(false);
                                if (pet[iPet].state != Pet.STATE_PHOENIX) {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq003);
                                } else {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].phoenixFightseq);
                                }
                                if (iArena == 0) {
                                    pet[iPet].mp -= mana[iSkill];
                                }
                                if (iArena == 1) {
                                    pet[iPet].mp -= 2 * mana[iSkill] / 3;
                                }
                                if (iArena == 2) {
                                    pet[iPet].mp -= 2 * mana[iSkill];
                                }
                                if (iArena == 3) {
                                    pet[iPet].mp -= mana[iSkill] / 2;
                                }
                            }
                            if (iSkill == 3) {
                                if (this.getWidth() >= 200) {
                                    hit.setImage(gameDesign.getGa_skill4(), 60, 60);
                                } else {
                                    hit.setImage(gameDesign.getGa_skill4128(), 40, 40);
                                }
                                int[] seq = {0, 1, 2};
                                hit.setFrameSequence(seq);
                                hit.setVisible(false);
                                if (pet[iPet].state != Pet.STATE_PHOENIX) {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq003);
                                } else {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].phoenixFightseq);
                                }
                                if (iArena == 0) {
                                    pet[iPet].mp -= mana[iSkill];
                                }
                                if (iArena == 1) {
                                    pet[iPet].mp -= 2 * mana[iSkill] / 3;
                                }
                                if (iArena == 2) {
                                    pet[iPet].mp -= 2 * mana[iSkill];
                                }
                                if (iArena == 3) {
                                    pet[iPet].mp -= mana[iSkill] / 2;
                                }
                            }
                            if (iSkill == 4) {
                                if (this.getWidth() >= 200) {
                                    hit.setImage(gameDesign.getGa_skill5(), 60, 60);
                                } else {
                                    hit.setImage(gameDesign.getGa_skill5128(), 40, 40);
                                }
                                int[] seq = {0, 1, 2};
                                hit.setFrameSequence(seq);
                                hit.setVisible(false);
                                if (pet[iPet].state != Pet.STATE_PHOENIX) {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq002);
                                } else {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].phoenixFightseq);
                                }
                                if (iArena == 0) {
                                    pet[iPet].mp -= mana[iSkill];
                                }
                                if (iArena == 1) {
                                    pet[iPet].mp -= 2 * mana[iSkill] / 3;
                                }
                                if (iArena == 2) {
                                    pet[iPet].mp -= 2 * mana[iSkill];
                                }
                                if (iArena == 3) {
                                    pet[iPet].mp -= mana[iSkill] / 2;
                                }
                            }
                            if (iSkill == 5 && iArena != 3) {
                                if (this.getWidth() >= 200) {
                                    hit.setImage(gameDesign.getGa_skill6(), 60, 60);
                                } else {
                                    hit.setImage(gameDesign.getGa_skill6128(), 40, 40);
                                }
                                int[] seq = {0, 0, 1, 1, 1, 2, 2, 2, 2, 2};
                                hit.setFrameSequence(seq);
                                hit.setVisible(false);
                                if (pet[iPet].state != Pet.STATE_PHOENIX) {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyFightseq005);
                                } else {
                                    pet[iPet].pet.setFrameSequence(pet[iPet].phoenixFightseq);
                                }
                                if (iArena == 2) {
                                    pet[iPet].mp -= mana[iSkill] / 2;
                                } else {
                                    if (iArena == 0) {
                                        pet[iPet].mp -= mana[iSkill];
                                    }
                                    if (iArena == 1) {
                                        pet[iPet].mp -= 2 * mana[iSkill];
                                    }
                                }
                            }
                            if (pet[iPet].mp < 0) {
                                pet[iPet].mp = 0;
                            }
                            checkAfterChooseSkill();
                            randomReBuffSkill();
                        }
                    }
                }
                if (listSkill.isVisible()) {
                    if (iSkill >= 6) {
//                        if (this.getWidth() > 200 || totalMemory > 1000000) {
//                            setNullImageSkill();
//                        }
                        if (this.getWidth() < 160) {
                            if (totalMemory < 1000000) {
                                setNullImageSkill();
                            }
                        }
                        if (!isYourTurn) {
                            if (pet[iPet].mp >= mana[iSkill]) {
                                lmFight.remove(buffSkill);
                                lmFight.insert(buffSkill, 0);
                                if (iSkill == 6) {
                                    if (this.getWidth() >= 200) {
                                        buffSkill.setImage(gameDesign.getGa_skill7(), 60, 60);
                                    } else {
                                        buffSkill.setImage(gameDesign.getGa_skill7128(), 40, 40);
                                    }
                                    buffSkill.setFrameSequence(gameDesign.chickBabySkill7seq001);
                                    buffSkill.setPosition(pet[iPet].getX() - (buffSkill.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (buffSkill.getHeight() - pet[iPet].pet.getHeight()) / 2);
                                    buffSkill.setVisible(true);
                                    isMySkill7 = true;
                                }
                                if (iSkill == 7) {
                                    if (this.getWidth() >= 200) {
                                        buffSkill.setImage(gameDesign.getGa_skill8(), 60, 60);
                                    } else {
                                        buffSkill.setImage(gameDesign.getGa_skill8128(), 40, 40);
                                    }
                                    buffSkill.setFrameSequence(gameDesign.chickBabySkill8seq001);
                                    buffSkill.setPosition(pet[iPet].getX() - (buffSkill.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (buffSkill.getHeight() - pet[iPet].pet.getHeight()) / 2);
                                    buffSkill.setVisible(true);
                                    isMySkill8 = true;
                                }
                                if (iSkill == 9) {
                                    if (this.getWidth() >= 200) {
                                        buffSkill.setImage(gameDesign.getGa_skill10(), 60, 60);
                                    } else {
                                        buffSkill.setImage(gameDesign.getGa_skill10128(), 40, 40);
                                    }
                                    buffSkill.setFrameSequence(gameDesign.chickBabySkill10seq001);
                                    buffSkill.setPosition(pet[iPet].getX() - (buffSkill.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (buffSkill.getHeight() - pet[iPet].pet.getHeight()) / 2);
                                    buffSkill.setVisible(true);
                                    isMySkill10 = true;
                                }
                                listSkill.setVisible(false);
                                pet[iPet].mp -= mana[iSkill];
                            }
                        } else {
                            if (pet[iPet].mp >= mana[iSkill]) {
//                                if (this.getWidth() > 200 || totalMemory > 1000000) {
//                                    setNullImageSkill();
//                                }
                                if (this.getWidth() < 160) {
                                    if (totalMemory < 1000000) {
                                        setNullImageSkill();
                                    }
                                }
                                if (iSkill == 8) {
                                    lmFight.remove(buffSkill);
                                    lmFight.insert(buffSkill, 12);
                                    if (this.getWidth() >= 200) {
                                        buffSkill.setImage(gameDesign.getGa_skill9(), 60, 60);
                                    } else {
                                        buffSkill.setImage(gameDesign.getGa_skill9128(), 40, 40);
                                    }
                                    buffSkill.setFrameSequence(gameDesign.chickBabySkill9seq001);
                                    buffSkill.setPosition(pet[iPet].getX() - (buffSkill.getWidth() - pet[iPet].pet.getWidth()) / 2, pet[iPet].getY() - (buffSkill.getHeight() - pet[iPet].pet.getHeight()) / 2);
                                    buffSkill.setVisible(true);
                                    isMySkill9 = true;
                                    pet[iPet].mp -= mana[iSkill];
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void upInfoMyPet() {
        if (iUpInfo == 0) {
            if (money >= costUpInfo[iUpInfo] && pet[iPet].skillPoint >= spUpInfo[iUpInfo]) {
                money -= costUpInfo[iUpInfo];
                pet[iPet].skillPoint -= spUpInfo[iUpInfo];
                pet[iPet].mp += 5;
                noUpMyInfo[0]++;
                costUpInfo[iUpInfo] += 300 * noUpMyInfo[0];
                spUpInfo[iUpInfo] += 15 * noUpMyInfo[0];
            }
        }
        if (iUpInfo == 1) {
            if (money >= costUpInfo[iUpInfo] && pet[iPet].skillPoint >= spUpInfo[iUpInfo]) {
                money -= costUpInfo[iUpInfo];
                pet[iPet].skillPoint -= spUpInfo[iUpInfo];
                pet[iPet].hp += 10;
                noUpMyInfo[1]++;
                costUpInfo[iUpInfo] += 500 * noUpMyInfo[1];
                spUpInfo[iUpInfo] += 25 * noUpMyInfo[1];
            }
        }
        if (iUpInfo == 2) {
            if (money >= costUpInfo[iUpInfo] && pet[iPet].skillPoint >= spUpInfo[iUpInfo]) {
                money -= costUpInfo[iUpInfo];
                pet[iPet].skillPoint -= spUpInfo[iUpInfo];
                pet[iPet].attack += 1;
                noUpMyInfo[2]++;
                costUpInfo[iUpInfo] += 1000 * noUpMyInfo[2];
                spUpInfo[iUpInfo] += 15 * noUpMyInfo[2];
            }
        }
        if (iUpInfo == 3) {
            if (money >= costUpInfo[iUpInfo] && pet[iPet].skillPoint >= spUpInfo[iUpInfo]) {
                money -= costUpInfo[iUpInfo];
                pet[iPet].skillPoint -= spUpInfo[iUpInfo];
                pet[iPet].defend += 1;
                noUpMyInfo[3]++;
                costUpInfo[iUpInfo] += 300 * noUpMyInfo[3];
                spUpInfo[iUpInfo] += 20 * noUpMyInfo[3];
            }
        }
    }

    public void checkAfterChooseSkill() {
        timeWaitChooseSkill = 10000;
        isHitting = true;
        listSkill.setVisible(false);
        addSkill.setVisible(false);
        isAttack = true;
        pet[iPet].pet.setFrame(0);
        if (this.getWidth() > 160) {
            addNenFight.setVisible(true);
            myWind.setVisible(true);
            myWind.setPosition(0, this.getHeight() / 2);
            doithuWind.setVisible(true);
            doithuWind.setTransform(Sprite.TRANS_MIRROR);
            doithuWind.setPosition(0, 0);
        }
        hit.setTransform(Sprite.TRANS_NONE);
        if (iSkill != 4) {
            lmFight.remove(hit);
            lmFight.insert(hit, 0);
            if (iSkill != 1) {
                hit.setPosition(pet[iPet].getX(), pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - hit.getHeight() / 2);
            } else {
                hit.setPosition(pet[iPet].getX(), pet[iPet].getY());
            }
        } else {
            lmFight.remove(hit);
            lmFight.insert(hit, 12);
            hit.setPosition(pet[iPet].getX(), pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - hit.getHeight() / 2);
        }
        if (iSkill == 5) {
            lmFight.remove(hit);
            lmFight.insert(hit, 0);
            hit.setPosition(petDoiThu.getX() - (hit.getWidth() / 2 - petDoiThu.pet.getWidth() / 2), petDoiThu.getY());
        }
        oneHit.setPosition(petDoiThu.getX() /*+ oneHit.getWidth() / 2*/, petDoiThu.getY() - (oneHit.getHeight() / 2 - petDoiThu.pet.getHeight() / 2));
    }

    public void okChoosePet() {
        iPet = iChoosePet;
        if (iChoosePet == 0) {
            if (midlet.infoPet1.isChosenPet) {
                numberArena = midlet.infoPet1.numberArena;
                if (numberArena > 0) {
                    key.setFrame(numberArena - 1);
                }
                isChooseEgg = false;
                isStartedGame = true;
//                if (!isInitMap) {
//                lm = new LayerManager();
//                lmInfo = new LayerManager();
//                lmFight = new LayerManager();
//                lmChoosePet = new LayerManager();
//                lmAnouceItem = new LayerManager();
//                lmPark = new LayerManager();
                initMainMap();
                initInfoMap();
                initFightMap();
                noBottleHP = midlet.infoPet1.noBottleHp;
                noBottleMP = midlet.infoPet1.noBottleMP;
                noFood = midlet.infoPet1.noFood;
                for (int i = 0; i < skilllv.length; i++) {
                    skilllv[i] = midlet.infoPet1.skilllv[i];
                }
                mana[0] = 0;
                mana[1] = 10;
                mana[2] = 20;
                mana[3] = 25;
                mana[4] = 50;
                mana[5] = 25;
                mana[6] = 80;
                mana[7] = 50;
                mana[8] = 75;
                mana[9] = 20;
                for (int i = 0; i < mana.length; i++) {
                    mana[i] += (skilllv[i] - 1) * 5;
                }
                dam[0] = 3;
                dam[1] = 5;
                dam[2] = 7;
                dam[3] = 9;
                dam[4] = 11;
                dam[5] = 7;
                dam[6] = dam[7] = dam[8] = dam[9] = 0;
                for (int i = 0; i < 6; i++) {
                    dam[i] += skilllv[i] - 1;
                }
                acc[0] = 100;
                acc[1] = 30;
                acc[2] = 30;
                acc[3] = 30;
                acc[4] = 30;
                acc[5] = 30;
                acc[6] = acc[7] = acc[8] = acc[9] = 0;
                for (int i = 1; i < 6; i++) {
                    if (skilllv[i] == 2) {
                        acc[i] = 50;
                    } else if (skilllv[i] >= 3) {
                        acc[i] = 100;
                    }
                }
                for (int i = 0; i < costSkill.length; i++) {
                    costSkill[i] = (i * 2 + 2) * 500 + 2 * skilllv[i] * 500;
                }
                for (int i = 0; i < spSkill.length; i++) {
                    if (i <= 3) {
                        spSkill[i] = 50 + 10 * 2 * (skilllv[i] - 1);
                    } else if (i < 6) {
                        spSkill[i] = 50 + 15 * 2 * (skilllv[i] - 1);
                    } else {
                        spSkill[i] = 50 + 20 * 2 * (skilllv[i] - 1);
                    }
//                    spSkill[i] = 1;
                }
                for (int i = 0; i < costUpInfo.length; i++) {
                    costUpInfo[i] = 2000;
                }
                for (int i = 0; i < spUpInfo.length; i++) {
                    spUpInfo[i] = 150;
                }
                for (int i = 0; i < noUpMyInfo.length; i++) {
                    noUpMyInfo[i] = midlet.infoPet1.noUpMyInfo[i];
                }
                costUpInfo[0] += 300 * noUpMyInfo[0];
                spUpInfo[0] += 15 * noUpMyInfo[0];
                costUpInfo[1] += 500 * noUpMyInfo[1];
                spUpInfo[1] += 25 * noUpMyInfo[1];
                costUpInfo[2] += 1000 * noUpMyInfo[2];
                spUpInfo[2] += 15 * noUpMyInfo[2];
                costUpInfo[3] += 300 * noUpMyInfo[3];
                spUpInfo[3] += 20 * noUpMyInfo[3];
                isKeyBonus = midlet.infoPet1.isKeyBonus;
//                    isInitMap = true;
//                }
                isExitPressed = false;
                pointer.setVisible(true);
            } else {
//                isChooseEgg = true;
                okChooseEgg();
            }
        } else {
            if (midlet.infoPet2.isChosenPet) {
                numberArena = midlet.infoPet2.numberArena;
                if (numberArena > 0) {
                    key.setFrame(numberArena - 1);
                }
                isChooseEgg = false;
                isStartedGame = true;
//                if (!isInitMap) {
//                lm = new LayerManager();
//                lmInfo = new LayerManager();
//                lmFight = new LayerManager();
//                lmChoosePet = new LayerManager();
//                lmAnouceItem = new LayerManager();
//                lmPark = new LayerManager();
                initMainMap();
                initInfoMap();
                initFightMap();
                noBottleHP = midlet.infoPet2.noBottleHp;
                noBottleMP = midlet.infoPet2.noBottleMP;
                noFood = midlet.infoPet2.noFood;
                for (int i = 0; i < skilllv.length; i++) {
                    skilllv[i] = midlet.infoPet2.skilllv[i];
                }
                mana[0] = 0;
                mana[1] = 10;
                mana[2] = 20;
                mana[3] = 25;
                mana[4] = 50;
                mana[5] = 25;
                mana[6] = 80;
                mana[7] = 50;
                mana[8] = 75;
                mana[9] = 20;
                for (int i = 0; i < mana.length; i++) {
                    mana[i] += (skilllv[i] - 1) * 5;
                }
                dam[0] = 3;
                dam[1] = 5;
                dam[2] = 7;
                dam[3] = 9;
                dam[4] = 11;
                dam[5] = 7;
                dam[6] = dam[7] = dam[8] = dam[9] = 0;
                for (int i = 0; i < 6; i++) {
                    dam[i] += skilllv[i] - 1;
                }
                acc[0] = 100;
                acc[1] = 30;
                acc[2] = 30;
                acc[3] = 30;
                acc[4] = 30;
                acc[5] = 30;
                acc[6] = acc[7] = acc[8] = acc[9] = 0;
                for (int i = 1; i < 6; i++) {
                    if (skilllv[i] == 2) {
                        acc[i] = 50;
                    } else if (skilllv[i] >= 3) {
                        acc[i] = 100;
                    }
                }
                for (int i = 0; i < costSkill.length; i++) {
                    costSkill[i] = (i * 2 + 2) * 500 + 2 * skilllv[i] * 500;
                }
                for (int i = 0; i < spSkill.length; i++) {
                    if (i <= 3) {
                        spSkill[i] = 50 + 10 * 2 * (skilllv[i] - 1);
                    } else if (i < 6) {
                        spSkill[i] = 50 + 15 * 2 * (skilllv[i] - 1);
                    } else {
                        spSkill[i] = 50 + 20 * 2 * (skilllv[i] - 1);
                    }
//                    spSkill[i] = 1;
                }
                for (int i = 0; i < costUpInfo.length; i++) {
                    costUpInfo[i] = 2000;
                }
                for (int i = 0; i < spUpInfo.length; i++) {
                    spUpInfo[i] = 150;
                }
                for (int i = 0; i < noUpMyInfo.length; i++) {
                    noUpMyInfo[i] = midlet.infoPet2.noUpMyInfo[i];
                }
                costUpInfo[0] += 300 * noUpMyInfo[0];
                spUpInfo[0] += 15 * noUpMyInfo[0];
                costUpInfo[1] += 500 * noUpMyInfo[1];
                spUpInfo[1] += 25 * noUpMyInfo[1];
                costUpInfo[2] += 1000 * noUpMyInfo[2];
                spUpInfo[2] += 15 * noUpMyInfo[2];
                costUpInfo[3] += 300 * noUpMyInfo[3];
                spUpInfo[3] += 20 * noUpMyInfo[3];
                isKeyBonus = midlet.infoPet2.isKeyBonus;
//                    isInitMap = true;
//                }
                isExitPressed = false;
                pointer.setVisible(true);
            } else {
                try {
                    okChooseEgg();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }

    public void okChooseEgg() {
        try {
            if (this.getWidth() >= 200) {
                pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga(), 26, 40), Pet.CHICK);
            } else {
                pet[iPet] = new Pet(new Sprite(gameDesign.getTrungga128(), 16, 25), Pet.CHICK);
            }
            if (iPet == 0) {
                pet[iPet].level = midlet.infoPet1.level;
            } else {
                pet[iPet].level = midlet.infoPet2.level;
            }
            pet[iPet].setName(Pet.CHICK);
            pet[iPet].setState(Pet.STATE_EGG, pet[iPet].chickEggSwayseq);
            lmChoosePet.append(pet[iPet].pet);
            pet[iPet].title = "Gà lửa" + (iPet + 1);
            if (this.getWidth() >= 160) {
                midlet.newPetName = new NewPetNameScreen(midlet, iPet);
                midlet.display.setCurrent(midlet.newPetName);
            } else {
                isChooseEgg = false;
                int[] skilllv1 = new int[10];
                for (int i = 0; i < skilllv1.length; i++) {
                    skilllv1[i] = 1;
                }
                int[] noUpMyInfo1 = new int[4];
                for (int i = 0; i < noUpMyInfo1.length; i++) {
                    noUpMyInfo1[i] = 0;
                }
                try {
//                        if (iPet == 0) {
//                            midlet.infoPet1.updateInfo(true, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pet[iPet].title, true, 1, 0, 0, 0, 0, 0, 0, 0, 0, skilllv1, noUpMyInfo1, false);
//                        } else {
//                            midlet.infoPet2.updateInfo(true, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pet[iPet].title, true, 1, 0, 0, 0, 0, 0, 0, 0, 0, skilllv1, noUpMyInfo1, false);
//                        }
                    saveInfoPet(iPet);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            money -= 500;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void upKey() {
        if (!isBeginFight) {
            if (!isInfoScreen) {
                if (isTrain && !isStartTrain) {

                    if (iArrow < 4) {
                        if (iInputArrow[iArrow] == MyCanvas.ARROW_UP) {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                        } else {
                            trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                            isTrainMissed = true;
                            isDrawTrainMiss = true;
                        }
                        iArrow++;
                    }
                    isArrowPressed = true;
                } else if (isWork) {
                    if (isMenuFight) {
                        if (iMenuFight > 0) {
                            iMenuFight--;
                        } else {
                            iMenuFight = 3;
                        }
                    }
//                    if (isDrawSkillFight) {
//                        if (iChooseSkillFight > 0) {
//                            iChooseSkillFight--;
//                        } else {
//                            iChooseSkillFight = listChooseSkill.getRows() - 1;
//                        }
//                    }
//                    if (isInfoFight) {
//                        if (iUpInfo > 0) {
//                            iUpInfo--;
//                        } else {
//                            iUpInfo = costUpInfo.length - 1;
//                        }
//                    }
                }
            } else {
                if (iInfo == 3) {
                    if (iUpInfo > 0) {
                        iUpInfo--;
                    } else {
                        iUpInfo = costUpInfo.length - 1;
                    }
                }
                if (iInfo == 4) {
                    if (iChooseSkillFight > 0) {
                        iChooseSkillFight--;
                    } else {
                        iChooseSkillFight = listChooseSkill.getRows() - 1;
                    }
                }
            }
        } else {
            if (iSkill >= 5) {
                iSkill -= 5;
            } else {
                iSkill += 5;
            }
        }
    }

    private void menuRightKey() {
        if (isStartedGame) {
            if (!isStartWalk) {
                if (!isExitPressed) {
                    if (!isWork) {
                        if (!isInfoScreen) {
                            if (isOpenSubMenu) {
                                if (!isFinishChamsoc && !isCleaning && !isLearning && !isEating && !isDoctor) {
                                    isSubBeginLeft = true;
                                    for (int i = 0; i < mainMenu.length; i++) {
                                        mainMenu[i].setPosition(this.getWidth() / 2 - mainMenu.length * mainMenu[i].getWidth() / 2 + i * mainMenu[i].getWidth(), this.getHeight());
                                    }
                                    iPointer = iMainMenu;
                                }
                            } else {
                                if (!isSavePetMss) {
                                    isLock = !isLock;
                                    for (int i = 0; i < mainMenu.length; i++) {
                                        mainMenu[i].setVisible(!isLock);
                                    }
                                    pointer.setVisible(!isLock);
                                } else {
                                    isSavePetMss = false;
                                }
                            }
                        } else {
                            isInfoScreen = false;
                            xInfo = 0;
                            for (int i = 0; i < subMenu1.length; i++) {
                                subMenu1[i].setPosition((i - subMenu1.length) * subMenu1[i].getWidth(), topMainMenu);
                                subMenu1[i].setVisible(true);
                            }
                            key.setVisible(false);
                            pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
                            pet[iPet].pet.setVisible(true);
                            iconFood.setVisible(false);
                            bottleHP.setVisible(false);
                            bottleMP.setVisible(false);
                        }
                    } else {
                        if (isTrain) {
                            isTrainBeginDown = true;
                            for (int i = 0; i < subMenu1.length; i++) {
                                subMenu1[i].setPosition((i - subMenu1.length) * subMenu1[i].getWidth(), topMainMenu);
                                subMenu1[i].setVisible(true);
                            }
                            pointer.setVisible(true);
                            pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
                            pet[iPet].pet.setVisible(true);
                            pet[iPet].isDance = false;
                            if (pet[iPet].level >= 2) {
                                if (pet[iPet].checkTired()) {
                                    pet[iPet].pet.setFrame(6);
                                } else {
                                    pet[iPet].pet.setFrame(18);
                                }
                                if (pet[iPet].relaxPoint > 0) {
                                    thinking.setVisible(false);
                                    iconThinking.setVisible(false);
                                }
                            }
                        }
                        if (isThiDau) {
                            if (isInfoFight) {
                                isInfoFight = false;
                                isMenuFight = true;
                                pet[iPet].pet.setVisible(false);
                            }
                            if (isChooseFight) {
                                isMenuFight = true;
                                isChooseFight = false;
                                choosenFight.setVisible(false);
                            }
                            if (isDrawInfoDoiThu) {
                                isMenuFight = true;
                                isDrawInfoDoiThu = false;
                                petDoiThu.pet.setVisible(false);
                            }
                            if (isBeginFight) {
                                if (!isHitting && !reHitting) {
                                    isMssFight = !isMssFight;
                                }
                            }
                            if (isDrawSkillFight) {
                                isDrawSkillFight = false;
                                isMenuFight = true;
                                listAddChooseSkill.setVisible(false);
                                listChooseSkill.setVisible(false);
                            }
                        }
                    }
                } else {
                    isExitPressed = false;
                    pointer.setVisible(true);
                }
            } else {
                if (!isExitWalk) {
                    isExitWalk = true;
                } else {
                    isExitWalk = false;
                }
            }
        } else {
            if (isChooseEgg) {
                isChooseEgg = false;
            } else {
                if (!isExitGamePressed) {
                    if (!isSellPet) {
                        isExitGamePressed = true;
                    } else {
                        isSellPet = false;
                    }
                } else {
                    isExitGamePressed = false;
                }
            }
        }
    }

    public void saveInfoPet(int iPet) {
        try {
            Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+7"));
            Date date = new Date();
            calendar.setTime(date);
            int date1 = calendar.get(Calendar.DATE);
            int hour1 = calendar.get(Calendar.HOUR);
            int min1 = calendar.get(Calendar.MINUTE);
            if (iPet == 0) {
                midlet.infoPet1.updateInfo(true, pet[iPet].level, pet[iPet].exp, pet[iPet].skillPoint, pet[iPet].hp, pet[iPet].mp, pet[iPet].attack, pet[iPet].defend, date1, hour1, min1, pet[iPet].name, pet[iPet].cost, pet[iPet].title, pet[iPet].checkTired(), numberArena, noBottleHP, noBottleMP, pet[iPet].foodPoint, pet[iPet].learnPoint, pet[iPet].relaxPoint, pet[iPet].cleanPoint, pet[iPet].helthPoint, noFood, skilllv, noUpMyInfo, isKeyBonus);
            } else {
                midlet.infoPet2.updateInfo(true, pet[iPet].level, pet[iPet].exp, pet[iPet].skillPoint, pet[iPet].hp, pet[iPet].mp, pet[iPet].attack, pet[iPet].defend, date1, hour1, min1, pet[iPet].name, pet[iPet].cost, pet[iPet].title, pet[iPet].checkTired(), numberArena, noBottleHP, noBottleMP, pet[iPet].foodPoint, pet[iPet].learnPoint, pet[iPet].relaxPoint, pet[iPet].cleanPoint, pet[iPet].helthPoint, noFood, skilllv, noUpMyInfo, isKeyBonus);
            }
            midlet.yourInfo.updateInfo(money);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void menuLeftKey() throws IOException {
        if (isStartedGame) {
            if (!isStartWalk) {
                if (isExitPressed) {
//                try {
//                    saveInfoPet(iPet);
////                petYoYo.exit();
//                } catch (Exception ex) {
//                    ex.printStackTrace();
//                }
                    isStartedGame = false;
                    isChooseEgg = false;
                } else {
                    if (!isSavePetMss) {
                        if (isWork) {
                            if (isThiDau) {
                                if (isBeginFight && isMssFight) {
                                    isBeginFight = false;
                                    isMenuFight = true;
                                    isMssFight = false;
                                    isHitting = false;
                                    reHitting = false;
                                    petDoiThu.pet.setVisible(false);
                                    pet[iPet].pet.setVisible(false);
                                    pet[iPet].mp = maxMPMe;
                                    pet[iPet].hp = maxHPMe;
                                    petDoiThu.mp = maxMPDoiThu;
                                    petDoiThu.hp = maxHPDoiThu;
                                    if (this.getWidth() > 200) {
                                        myHPLine.setVisible(false);
                                        myHpMp.setVisible(false);
                                        doithuHPline.setVisible(false);
                                        doithuHpMp.setVisible(false);
                                    }
                                    oneHit.setVisible(false);
//                                creatHit.setVisible(false);
                                    hit.setVisible(false);
                                    listSkill.setVisible(false);
                                    addSkill.setVisible(false);
                                    if (myArena != null) {
                                        myArena.setVisible(false);
                                        doithuArena.setVisible(false);
                                    }
                                    bottleHP.setVisible(false);
                                    bottleMP.setVisible(false);
                                    dtBottleHP.setVisible(false);
                                    dtBottleMP.setVisible(false);
                                    buffSkill.setVisible(false);
                                    if (myWind != null) {
                                        myWind.setVisible(false);
                                        doithuWind.setVisible(false);
                                    }
                                    petDoiThu.pet.setFrame(0);
                                }
                            }
                        }
                        if (!isThiDau && !isTrain && !isOpenSubMenu && !isInfoScreen && !isPresentItem && !isSavePetMss && !isMainBeginDown && !isMainBeginUp && !isSubBeginLeft && !isSubBeginRight) {
                            isExitPressed = true;
                            pointer.setVisible(false);
                            try {
                                gameMedia.stop();
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                        }
                    } else {
                        if (money >= moneySavePet) {
                            money -= moneySavePet;
                            this.saveInfoPet(iPet);
                            isSavePetMss = false;
                            isSavePetSuccess = true;
                            isSavedPet = true;
                        }
                    }
                }
            } else {
                if (isExitWalk) {
                    isStartWalk = false;
                    isExitWalk = false;
                    if (pet[iPet].state == Pet.STATE_CHICK_SMALL) {
                        pet[iPet].pet.setImage(gameDesign.getGaCon(), 40, 40);
                    } else if (pet[iPet].state == Pet.STATE_CHICK_MEDIUM) {
                        pet[iPet].pet.setImage(gameDesign.getGaTrungBinh(), 60, 60);
                    } else if (pet[iPet].state == Pet.STATE_CHICK_BIG) {
                        pet[iPet].pet.setImage(gameDesign.getGaLon(), 70, 70);
                    }
                    pet[iPet].pet.setTransform(Sprite.TRANS_NONE);
                    if (pet[iPet].getState() == Pet.STATE_CHICK_SMALL) {
                        pet[iPet].pet.setFrameSequence(pet[iPet].chickBabyseq);
                    }
                    if (pet[iPet].getState() == Pet.STATE_CHICK_MEDIUM) {
                        pet[iPet].pet.setFrameSequence(pet[iPet].chickMediumseq);
                    }
                    if (pet[iPet].getState() == Pet.STATE_CHICK_BIG) {
                        pet[iPet].pet.setFrameSequence(pet[iPet].chickMediumseq);
                    }
                    pet[iPet].pet.setPosition(this.getWidth() / 2 - pet[iPet].pet.getWidth() / 2, 3 * this.getHeight() / 4 - pet[iPet].pet.getHeight());
                    face.setPosition(this.getWidth() / 2 - face.getWidth() / 2, pet[iPet].getY() + pet[iPet].pet.getHeight() / 2 - face.getHeight() / 2);
                }
            }
        } else {
            iPet = iChoosePet;
            if (isExitGamePressed) {
                try {
                    midlet.yourInfo.updateInfo(money);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                midlet.exit();
            } else {
                if (!isSellPet) {
                    isSellPet = true;
                } else {
                    sellPet(iChoosePet);
                }
            }
        }
    }

    private void leftkey() {
        if (isStartedGame) {
            if (!isStartWalk) {
                if (!isExitPressed) {
                    if (!isSavePetMss) {
                        if (!isWork) {
                            if (!isInfoScreen) {
                                if (!isOpenSubMenu) {
                                    if (iMainMenu > 0) {
                                        iMainMenu--;
                                    } else {
                                        iMainMenu = mainMenu.length - 1;
                                    }
                                    iPointer = iMainMenu;
                                } else {
                                    if (iMainMenu == 0) {
                                        if (pointer.isVisible()) {
                                            if (iSubMenu1 > 0) {
                                                iSubMenu1--;
                                            } else {
                                                iSubMenu1 = subMenu1.length - 1;
                                            }
                                            iPointer = iSubMenu1;
                                        }
                                    }
                                    if (iMainMenu == 2) {
                                        if (iSubMenu3 > 0) {
                                            iSubMenu3--;
                                        } else {
                                            iSubMenu3 = subMenu3.length - 1;
                                        }
                                        iPointer = iSubMenu3;
                                    }
                                }
                            } else {
                                if (iInfo > 0) {
                                    iInfo--;
                                } else {
                                    iInfo = 4;
                                }
                                xState = xInfo = 0;
                            }
                        } else {
                            if (isTrain && !isStartTrain) {

                                if (iArrow < 4) {
                                    if (iInputArrow[iArrow] == MyCanvas.ARROW_LEFT) {
                                        trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                                    } else {
                                        trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                                        isTrainMissed = true;
                                        isDrawTrainMiss = true;
                                    }
                                    iArrow++;
                                }
                                isArrowPressed = true;
                            }
                            if (isThiDau) {
                                if (isChooseFight) {
                                    if (iChooseFight > 0) {
                                        iChooseFight--;
                                    } else {
                                        iChooseFight = 4;
                                    }
                                } else if (isBeginFight) {
//                                if (iSkill > 0) {
//                                    iSkill--;
//                                } else {
//                                    iSkill = listSkill.getColumns() - 1;
//                                }
                                    if (iSkill < 5) {
                                        if (iSkill > 0) {
                                            iSkill--;
                                        } else {
                                            iSkill = 4;
                                        }
                                    } else {
                                        if (iSkill > 5) {
                                            iSkill--;
                                        } else {
                                            iSkill = 9;
                                        }
                                    }
                                } else if (isChooseArena) {
                                    if (iArena > 0) {
                                        iArena--;
                                    } else {
                                        iArena = nameArena.length - 1;
                                    }
                                    if (this.getWidth() > 200 || totalMemory > 1000000) {
                                        setImageArena();
                                    }
                                }
                            }
                        }
                    } else {
                        isOKSavePet = !isOKSavePet;
                    }
                } else {
                    isOKMssB = !isOKMssB;
                }
            }
        } else {
            if (isChooseEgg) {
                if (iEgg > 0) {
                    iEgg--;
                } else {
                    iEgg = 1;
                }
            } else {
                if (iChoosePet > 0) {
                    iChoosePet--;
                } else {
                    iChoosePet = 1;
                }
            }
        }
    }

    private void rightkey() {
        if (isStartedGame) {
            if (!isStartWalk) {
                if (!isExitPressed) {
                    if (!isSavePetMss) {
                        if (!isWork) {
                            if (!isInfoScreen) {
                                if (!isOpenSubMenu) {
                                    if (iMainMenu < mainMenu.length - 1) {
                                        iMainMenu++;
                                    } else {
                                        iMainMenu = 0;
                                    }
                                    iPointer = iMainMenu;
                                } else {
                                    if (iMainMenu == 0) {
                                        if (pointer.isVisible()) {
                                            if (iSubMenu1 < subMenu1.length - 1) {
                                                iSubMenu1++;
                                            } else {
                                                iSubMenu1 = 0;
                                            }
                                            iPointer = iSubMenu1;
                                        }
                                    }
                                    if (iMainMenu == 2) {
                                        if (iSubMenu3 < subMenu3.length - 1) {
                                            iSubMenu3++;
                                        } else {
                                            iSubMenu3 = 0;
                                        }
                                        iPointer = iSubMenu3;
                                    }
                                }
                            } else {
                                if (iInfo < 4) {
                                    iInfo++;
                                } else {
                                    iInfo = 0;
                                }
                                xState = xInfo = 0;
                            }
                        } else {
                            if (isTrain && !isStartTrain) {

                                if (iArrow < 4) {
                                    if (iInputArrow[iArrow] == MyCanvas.ARROW_RIGHT) {
                                        trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] - 4);
                                    } else {
                                        trainArrow.setCell(iArrow, 0, iInputArrow[iArrow] + 4);
                                        isTrainMissed = true;
                                        isDrawTrainMiss = true;
                                    }
                                    iArrow++;
                                }
                                isArrowPressed = true;
                            }
                            if (isThiDau) {
                                if (isChooseFight) {
                                    if (iChooseFight < 4) {
                                        iChooseFight++;
                                    } else {
                                        iChooseFight = 0;
                                    }
                                } else if (isBeginFight) {
                                    if (iSkill < 5) {
                                        if (iSkill < 4) {
                                            iSkill++;
                                        } else {
                                            iSkill = 0;
                                        }
                                    } else {
                                        if (iSkill < 9) {
                                            iSkill++;
                                        } else {
                                            iSkill = 5;
                                        }
                                    }
                                } else if (isChooseArena) {
                                    if (iArena < nameArena.length - 1) {
                                        iArena++;
                                    } else {
                                        iArena = 0;
                                    }
                                    setImageArena();
                                }
                            }
                        }
                    } else {
                        isOKSavePet = !isOKSavePet;
                    }
                } else {
                    isOKMssB = !isOKMssB;
                }
            }
        } else {
            if (isChooseEgg) {
                if (iEgg < 1) {
                    iEgg++;
                } else {
                    iEgg = 0;
                }
            } else {
                if (iChoosePet < 1) {
                    iChoosePet++;
                } else {
                    iChoosePet = 0;
                }
            }
        }
    }

    public void setImageArena() {
        try {
            if (this.getWidth() >= 160) {
                if (iArena == 0) {
                    myArena.setImage(gameDesign.getDau_truong1(), 240, 160);
                    doithuArena.setImage(gameDesign.getDau_truong1(), 240, 160);
                }
                if (iArena == 1) {
                    myArena.setImage(gameDesign.getDau_truong2(), 240, 160);
                    doithuArena.setImage(gameDesign.getDau_truong2(), 240, 160);
                }
                if (iArena == 2) {
                    myArena.setImage(gameDesign.getDau_truong3(), 240, 160);
                    doithuArena.setImage(gameDesign.getDau_truong3(), 240, 160);
                }
                if (iArena == 3) {
                    myArena.setImage(gameDesign.getDau_truong4(), 240, 160);
                    doithuArena.setImage(gameDesign.getDau_truong4(), 240, 160);
                }
            } else {
                if (totalMemory > 1000000 && this.getWidth() < 160) {
                    gameDesign.dau_truong1128 = null;
                    gameDesign.dau_truong2128 = null;
                    gameDesign.dau_truong3128 = null;
                    gameDesign.dau_truong4128 = null;
                    if (iArena == 0) {
                        myArena.setImage(gameDesign.getDau_truong1128(), 128, 100);
                        doithuArena.setImage(gameDesign.getDau_truong1128(), 128, 100);
                    }
                    if (iArena == 1) {
                        myArena.setImage(gameDesign.getDau_truong2128(), 128, 100);
                        doithuArena.setImage(gameDesign.getDau_truong2128(), 128, 100);
                    }
                    if (iArena == 2) {
                        myArena.setImage(gameDesign.getDau_truong3128(), 128, 100);
                        doithuArena.setImage(gameDesign.getDau_truong3128(), 128, 100);
                    }
                    if (iArena == 3) {
                        myArena.setImage(gameDesign.getDau_truong4128(), 128, 100);
                        doithuArena.setImage(gameDesign.getDau_truong4128(), 128, 100);
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void setNullImageSkill() {
        gameDesign.ga_skill1128 = null;
        gameDesign.ga_skill2128 = null;
        gameDesign.ga_skill3128 = null;
        gameDesign.ga_skill4128 = null;
        gameDesign.ga_skill5128 = null;
        gameDesign.ga_skill6128 = null;
        gameDesign.ga_skill7128 = null;
        gameDesign.ga_skill8128 = null;
        gameDesign.ga_skill9128 = null;
        gameDesign.ga_skill10128 = null;
        Runtime.getRuntime().gc();
    }

    public void setNullImageChick() {
        if (gameDesign.gaCon128 != null) {
            gameDesign.gaCon128 = null;
        }
        if (gameDesign.gaTrungBinh128 != null) {
            gameDesign.gaTrungBinh128 = null;
        }
        if (gameDesign.gaLon128 != null) {
            gameDesign.gaLon128 = null;
        }
        Runtime.getRuntime().gc();
    }

    public void setNullImageChickFight() {
        if (gameDesign.ga_con_chien_dau128 != null) {
            gameDesign.ga_con_chien_dau128 = null;
        }
        if (gameDesign.ga_lon_chien_dau128 != null) {
            gameDesign.ga_lon_chien_dau128 = null;
        }
        if (gameDesign.ga_trungbinh_chien_dau128 != null) {
            gameDesign.ga_trungbinh_chien_dau128 = null;
        }
        Runtime.getRuntime().gc();
    }

    public void checkInput2() {
        boolean bl = true;
        boolean bl2 = true;
        for (int i = 0; i < petDoiThu1.length; i++) {
            if (pet[iPet].pet.collidesWith(petDoiThu1[i].pet, true)) {
                isCollidesPet = true;
                iChooseFight = i;
                if (i == oldICollides) {
                    isInPutMove = true;
                } else {
                    prevDirect = this.lastDirection;
                    oldICollides = i;
                    isInPutMove = false;
                }
                bl = false;
                break;
            } else {
                isCollidesPet = false;
            }
        }
        if (bl) {
            oldICollides = -1;
            isInPutMove = true;
            prevDirect = -1;
        }
        for (int i = 0; i < cautruot.length; i++) {
            if (pet[iPet].pet.collidesWith(cautruot[i], true)) {
                if (i == oldICauTruot) {
                    isInputMoveCautruot = true;
                } else {
                    prevCauTruot = this.lastDirection;
                    oldICauTruot = i;
                    isInputMoveCautruot = false;
                }
                bl2 = false;
                break;
            }
        }
        if (bl2) {
            oldICauTruot = -1;
            isInputMoveCautruot = true;
            prevCauTruot = -1;
        }
    }

    public boolean checkInputWaterRIGHT() {
        boolean bl = true;
        if (pet[iPet].getY() + pet[iPet].pet.getHeight() > this.getHeight() - 75) {
            if (pet[iPet].getX() + pet[iPet].pet.getWidth() + 4 > 420 && pet[iPet].getX() < 960) {
                bl = false;
            }
        }
        return bl;
    }

    public boolean checkInputWaterDOWN() {
        boolean bl = true;
        if (pet[iPet].getX() > 420 && pet[iPet].getX() + pet[iPet].pet.getWidth() < 960) {
            if (pet[iPet].getY() + pet[iPet].pet.getHeight() + 4 > this.getHeight() - 75) {
                bl = false;
            }
        }
        return bl;
    }

    public boolean checkInputWaterLEFT() {
        boolean bl = true;
        if (pet[iPet].getY() + pet[iPet].pet.getHeight() > this.getHeight() - 75) {
            if (pet[iPet].getX() - 4 < 960 && pet[iPet].getX() - 4 > 420) {
                bl = false;
            }
        }
        return bl;
    }

    public void setGold() {
         money += 1000;
    }
}
